Форум: "Начинающим";
Текущий архив: 2007.11.11;
Скачать: [xml.tar.bz2];
ВнизПеревод Си -> Паскаль... Найти похожие ветки
← →
DelphiCoder (2007-10-18 13:26) [0]Доброго времени суток...
Помогите пожайлуста перевести код с Си на дельфи...
#define KEY_PRESSED(i) ((DWORD)( ((DWORD)GetAsyncKeyState(i))&0x8001) == 0x8001)
#define KEY_TOGGLED(i) ((DWORD)( ((DWORD)GetAsyncKeyState(i))&0x8001) == 0x8000)
{
HKL cLayoutRemote;
UCHAR KeyState[256];
DWORD dwDelay,dwCh;
SystemParametersInfo(SPI_GETKEYBOARDSPEED,0,&dwDelay,0);
for(;;)
{
cLayoutRemote = (HKL)((DWORD)GetKeyboardLayout(
GetWindowThreadProcessId(GetForegroundWindow(),NULL))&0xFFFF);
//~ !!! IMPORTANT!!! Must call GetKeyState(VK_CAPITAL) first.
//~ If not CASE of char will be invalid.
GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
for (UCHAR i = 0x00;i < 0xFF;i++)
{
if(KEY_PRESSED(i) && (ToAsciiEx(i,MapVirtualKeyEx(i,0,cLayoutRemote),KeyState,(WORD*)&dwCh,0,cLayoutR emote)) )
{
CharToOem((char*)&dwCh,(char*)&dwCh);
printf("%02x - %c\n",i,dwCh);
}
}
Sleep(dwDelay/4);
}
return(0);
}
← →
DelphiCoder (2007-10-18 13:27) [1]У меня пока получилось только так:
var
dwCh: TStr;
dwDelay, i: Dword;
cLayoutRemote: Hkl;
KeyState: TKeyboardState;
begin
SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, @dwDelay, 0);
while true do
begin
cLayoutRemote := GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, nil));
GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
for i := 0 to 255 do
begin
if GetAsyncKeyState(KeyState[i]) <> 0 then
ToAsciiEx(i,
MapVirtualKeyEx(i, 0, cLayoutRemote),
KeyState,
dwCh,
0,
cLayoutRemote);
if dwCh <> "" then MessageBox(0, dwCh, "", 0);
end;
Sleep(dwDelay);
end;
end;
← →
Jeer © (2007-10-18 16:34) [2]Главное, что получилось.
← →
DevilDevil © (2007-10-18 16:57) [3]Может так проще будет...
function KEY_PRESSED(Key : DWORD) : boolean;
begin
Result := (GetAsyncKeyState(Key) and $8001) = 8001;
end;
function KEY_TOGGLED(Key : DWORD) : boolean;
begin
Result := (GetAsyncKeyState(Key) and $8001) = 8000;
end;
← →
DelphiCoder (2007-10-18 18:28) [4]Пробую сделать так:
type
TStr = array [Byte] of Char;
function KEY_PRESSED(Key : DWORD) : boolean;
begin
Result := (GetAsyncKeyState(Key) and $8001) = 8001;
end;
procedure KeyLogThread;
var
dwCh: TStr;
dwDelay, i: Dword;
cLayoutRemote: Hkl;
KeyState: TKeyboardState;
begin
SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, @dwDelay, 0);
while true do
begin
cLayoutRemote := GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, nil));
GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
for i := 0 to 255 do
begin
if KEY_PRESSED(i) then
begin
ToAsciiEx(i,
MapVirtualKeyEx(i, 0, cLayoutRemote),
KeyState,
dwCh,
0,
cLayoutRemote);
MessageBox(0, dwCh, "", 0);
end;
end;
Sleep(dwDelay div 4);
end;
end;
var
Mes: Msg;
begin
PostMessage(0, WM_NULL, 0, 0);
GetMessage(Mes, 0, 0, 0);
KeyLogThread;
end.
Не работает =(
Вот полный рабочий исходник в си:#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma hdrstop
//-----------------------------------------------------------------------------
//~ 0x8001 equ toggled or pressed
#define KEY_PRESSED(i) ((DWORD)( ((DWORD)GetAsyncKeyState(i))&0x8001) == 0x8001)
#define KEY_TOGGLED(i) ((DWORD)( ((DWORD)GetAsyncKeyState(i))&0x8001) == 0x8000)
//-----------------------------------------------------------------------------
int printf(char *f, ...)
{
char s[1024];
va_list a;
unsigned long l;
va_start(a,f);
WriteFile((HANDLE)STD_OUTPUT_HANDLE,s,wvsprintf(s,f,a),&l,NULL);
va_end(a);
return(l);
}
//-----------------------------------------------------------------------------
int KeyLogThread()
{
HKL cLayoutRemote;
UCHAR KeyState[256];
DWORD dwDelay,dwCh;
SystemParametersInfo(SPI_GETKEYBOARDSPEED,0,&dwDelay,0);
for(;;)
{
cLayoutRemote = (HKL)((DWORD)GetKeyboardLayout(
GetWindowThreadProcessId(GetForegroundWindow(),NULL))&0xFFFF);
//~ !!! IMPORTANT!!! Must call GetKeyState(VK_CAPITAL) first.
//~ If not CASE of char will be invalid.
GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
for (UCHAR i = 0x00;i < 0xFF;i++)
{
if(KEY_PRESSED(i) && (ToAsciiEx(i,MapVirtualKeyEx(i,0,cLayoutRemote),KeyState,(WORD*)&dwCh,0,cLayoutR emote)) )
{
CharToOem((char*)&dwCh,(char*)&dwCh);
printf("%02x - %c\n",i,dwCh);
}
}
Sleep(dwDelay/4);
}
return(0);
}
//-----------------------------------------------------------------------------
int main()
{
//~ to avoid freezing
MSG msg;
PostMessage(NULL,WM_NULL,0,0);
GetMessage(&msg,NULL,0,0);
return(KeyLogThread());
}
//-----------------------------------------------------------------------------
← →
DelphiCoder (2007-10-18 18:55) [5]Из этого кода меня интересует только преобразование кода символа в сам символ.
← →
DelphiCoder (2007-10-18 19:01) [6]Делаю так:
cLayoutRemote := GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, nil) or $FFFF);
GetKeyState(VK_CAPITAL);
GetKeyboardState(KeyState);
i := lpMsg.wParam;
ToAsciiEx(i,
MapVirtualKeyEx(i, 0, cLayoutRemote),
KeyState,
szBuf,
0,
cLayoutRemote);
Не работает так, как нужно подскажите плиз где ошибка =(
Страницы: 1 вся ветка
Форум: "Начинающим";
Текущий архив: 2007.11.11;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.042 c