钩子问题(0分)

  • 主题发起人 主题发起人 yyok
  • 开始时间 开始时间
Y

yyok

Unregistered / Unconfirmed
GUEST, unregistred user!
有一种钩子叫键盘记录钩子WH_JOURNALPLAYBACK,请问如何使用它。
 
大部分类型的钩子都在这儿了。<br><br><br>----------这是*.dll中的单元---------------<br>unit HookProc;<br><br><br>interface<br><br>uses windows,messages,sysutils;<br><br>const<br>&nbsp; HTName:array[1..13] of pchar=(<br>&nbsp; 'CALLWNDPROC','CALLWNDPROCRET','CBT','DEBUG','GETMESSAGE','JOURNALPLAYBACK',<br>&nbsp; 'JOURNALRECORD','KEYBOARD','MOUSE','MSGFILTER','SHELL','SYSMSGFILTER','FOREGROUNDIDLE'<br>&nbsp; );<br><br><br>function CallWndProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function CallWndRetProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function CBTProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function DebugProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function GetMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function JournalPlaybackProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function JournalRecordProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function KeyboardProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function MouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function MessageProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function ShellProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function SysMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>function ForegroundIdleProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br><br>implementation<br><br>procedure SaveInfo(k:integer;str:string);stdcall;<br>var<br>&nbsp; f:textfile;<br>&nbsp; WorkPath:string;<br>begin<br>&nbsp; WorkPath:=ExtractFilePath(ParamStr(0));<br>&nbsp; assignfile(f,WorkPath+'Records.txt');<br>&nbsp; if fileexists(WorkPath+'Records.txt')=false then rewrite(f)<br>&nbsp; else append(f);<br>&nbsp; //if strcomp(pchar(str),pchar('#13#10'))=0 then writeln(f,'')<br>&nbsp; //else write(f,str);<br>&nbsp; writeln(f,HTName[k]+'----'+str);<br>&nbsp; closefile(f);<br>end;<br><br><br><br>function CallWndProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br>&nbsp; pcs:TCWPSTRUCT;<br>begin<br>&nbsp; pcs:=TCWPSTRUCT(PCWPSTRUCT(lParam)^);<br>&nbsp; if nCode&gt;=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; if pcs.message=wm_lbuttonup then<br>&nbsp; &nbsp; SaveInfo(1,format('hwnd=%x',[pcs.hwnd]));<br>&nbsp; end;<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function CallWndRetProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function CBTProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function DebugProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function GetMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>var<br>&nbsp; pcs:TMSG;<br>begin<br>&nbsp; pcs:=TMSG(PMSG(lParam)^);<br>&nbsp; if nCode&gt;=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; if pcs.message=wm_lbuttonup then<br>&nbsp; &nbsp; SaveInfo(5,format('hwnd=%x',[pcs.hwnd]));<br>&nbsp; end;<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function JournalPlaybackProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function JournalRecordProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function KeyboardProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function MouseProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function MessageProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function ShellProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function SysMsgProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br>//<br>function ForegroundIdleProc(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>begin<br>&nbsp; Result:=CallNextHookEx(0,nCode,wParam,lParam);<br>end;<br><br><br>end.<br><br><br><br>--------这是*.dll主程序------------------<br>library DemoHook;<br><br>uses<br>&nbsp; windows,messages,sysutils,<br>&nbsp; HookProc in 'HookProc.pas';<br><br>{$r *.res}<br><br>const<br><br>&nbsp; HookMemFileName='DllHookMemFile.DTA';<br>&nbsp; HTName:array[1..13] of pchar=(<br>&nbsp; 'CALLWNDPROC','CALLWNDPROCRET','CBT','DEBUG','GETMESSAGE','JOURNALPLAYBACK',<br>&nbsp; 'JOURNALRECORD','KEYBOARD','MOUSE','MSGFILTER','SHELL','SYSMSGFILTER','FOREGROUNDIDLE'<br>&nbsp; );<br><br>type<br>&nbsp; THookProc = function(nCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;<br>&nbsp; PShared=^TShared;<br>&nbsp; THook = record<br>&nbsp; &nbsp; HookHand:HHook;<br>&nbsp; &nbsp; HookType:integer;<br>&nbsp; &nbsp; HookProc:THookProc;<br>&nbsp; end;<br>&nbsp; TShared = record<br>&nbsp; &nbsp; Hook:array [0..16] of THook;<br>&nbsp; &nbsp; Father,Self:integer;<br>&nbsp; &nbsp; Count:integer;<br>&nbsp; &nbsp; hinst:integer;<br>&nbsp; end;<br>&nbsp; TWin = record<br>&nbsp; &nbsp; Msg:TMsg;<br>&nbsp; &nbsp; wClass:TWndClass;<br>&nbsp; &nbsp; hMain:integer;<br>&nbsp; end;<br>var<br>&nbsp; MemFile:THandle;<br>&nbsp; Shared:PShared;<br>&nbsp; Win:TWin;<br>&nbsp; wmhook:integer;<br><br>procedure SaveInfo(k:integer;str:string);stdcall;<br>var<br>&nbsp; f:textfile;<br>&nbsp; WorkPath:string;<br>begin<br>&nbsp; WorkPath:=ExtractFilePath(ParamStr(0));<br>&nbsp; assignfile(f,WorkPath+'Records.txt');<br>&nbsp; if fileexists(WorkPath+'Records.txt')=false then rewrite(f)<br>&nbsp; else append(f);<br>&nbsp; //if strcomp(pchar(str),pchar('#13#10'))=0 then writeln(f,'')<br>&nbsp; //else write(f,str);<br>&nbsp; writeln(f,HTName[k]+'----'+str);<br>&nbsp; closefile(f);<br>end;<br><br><br>procedure InitHookData;<br>var k:integer;<br>begin<br>&nbsp; with Shared^ do<br>&nbsp; begin<br>&nbsp; &nbsp; for k:=0 to 14 do Hook[k].HookHand:=0;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[0].HookType:=WH_CALLWNDPROC;<br>&nbsp; &nbsp; Hook[0].HookProc:=@CallWndProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[1].HookType:=WH_CALLWNDPROCRET;<br>&nbsp; &nbsp; Hook[1].HookProc:=@CallWndRetProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[2].HookType:=WH_CBT;<br>&nbsp; &nbsp; Hook[2].HookProc:=@CBTProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[3].HookType:=WH_DEBUG;<br>&nbsp; &nbsp; Hook[3].HookProc:=@DebugProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[4].HookType:=WH_GETMESSAGE;<br>&nbsp; &nbsp; Hook[4].HookProc:=@GetMsgProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[5].HookType:=WH_JOURNALPLAYBACK;<br>&nbsp; &nbsp; Hook[5].HookProc:=@JournalPlaybackProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[6].HookType:=WH_JOURNALRECORD;<br>&nbsp; &nbsp; Hook[6].HookProc:=@JournalRecordProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[7].HookType:=WH_KEYBOARD;<br>&nbsp; &nbsp; Hook[7].HookProc:=@KeyboardProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[8].HookType:=WH_MOUSE;<br>&nbsp; &nbsp; Hook[8].HookProc:=@MouseProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[9].HookType:=WH_MSGFILTER;<br>&nbsp; &nbsp; Hook[9].HookProc:=@MessageProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[10].HookType:=WH_SHELL &nbsp; &nbsp;;<br>&nbsp; &nbsp; Hook[10].HookProc:=@ShellProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[11].HookType:=WH_SYSMSGFILTER;<br>&nbsp; &nbsp; Hook[11].HookProc:=@SysMsgProc;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; Hook[12].HookType:=WH_FOREGROUNDIDLE;<br>&nbsp; &nbsp; Hook[12].HookProc:=@ForegroundIdleProc;<br><br>&nbsp; end;<br>end;<br><br>function SetHook(fSet:boolean;HookId:integer):bool;stdcall;<br>begin<br>&nbsp; with shared^ do<br>&nbsp; if fSet=true then<br>&nbsp; begin<br>&nbsp; &nbsp; if Hook[HookId].HookHand=0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Hook[HookId].HookHand:=SetWindowsHookEx(Hook[HookId].HookType,Hook[HookId].HookProc,hinstance,0);<br>&nbsp; &nbsp; &nbsp; if Hook[HookId].HookHand&lt;&gt;0 then Result:=true<br>&nbsp; &nbsp; &nbsp; else Result:=false;<br>&nbsp; &nbsp; end else Result:=true;<br>&nbsp; end else<br>&nbsp; begin<br>&nbsp; &nbsp; if Hook[HookId].HookHand&lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if UnhookWindowsHookEx(Hook[HookId].HookHand)=true then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Hook[HookId].HookHand:=0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:=true;<br>&nbsp; &nbsp; &nbsp; end else Result:=false;<br>&nbsp; &nbsp; end else Result:=true;<br>&nbsp; end;<br>end;<br><br>procedure Extro;<br>begin<br>&nbsp; UnmapViewOfFile(Shared);<br>&nbsp; CloseHandle(MemFile);<br>end;<br><br><br>function WindowProc(hWnd,Msg,wParam,lParam:longint):LRESULT; stdcall;<br>var k:integer;<br>begin<br>&nbsp; Result:=DefWindowProc(hWnd,Msg,wParam,lParam);<br>&nbsp; case Msg of<br>&nbsp; wm_destroy:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; for k:=0 to 12 do SetHook(False,k);<br>&nbsp; &nbsp; &nbsp; postmessage(findwindow('WinHook',nil),wm_destroy,0,0);<br>&nbsp; &nbsp; &nbsp; ExitThread(0);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; if msg=wmhook then<br>&nbsp; begin<br>&nbsp; &nbsp; if wparam&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if sethook(true,wparam-1)=true then postmessage(findwindow('WinHook',nil),wmhook,wparam,0);<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if sethook(false,-wparam-1)=true then postmessage(findwindow('WinHook',nil),wmhook,wparam,0);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure run;stdcall;<br>//var k:integer;<br>begin<br>&nbsp; win.wClass.lpfnWndProc:= &nbsp;@WindowProc;<br>&nbsp; win.wClass.hInstance:= &nbsp; &nbsp;hInstance;<br>&nbsp; win.wClass.lpszClassName:='WideHook';<br>&nbsp; RegisterClass(win.wClass);<br>&nbsp; win.hmain:=CreateWindowEx(ws_ex_toolwindow,win.wClass.lpszClassName,'WideHook',WS_CAPTION,0,0,1,1,0,0,hInstance,nil);<br>&nbsp; FillChar(Shared^,SizeOf(TShared),0);<br>&nbsp; shared^.self:=win.hmain;<br>&nbsp; shared^.hinst:=hinstance;<br>&nbsp; InitHookData;<br>&nbsp; wmhook:=registerwindowmessage(pchar('wm_hook'));<br>&nbsp; while(GetMessage(win.Msg,win.hmain,0,0))do<br>&nbsp; begin<br>&nbsp; &nbsp; TranslateMessage(win.Msg);<br>&nbsp; &nbsp; DispatchMessage(win.Msg);<br>&nbsp; end;<br>end;<br><br>procedure DllEntryPoint(fdwReason:DWORD);<br>begin<br>&nbsp; case fdwReason of<br>&nbsp; DLL_PROCESS_DETACH:<br>&nbsp; &nbsp; Extro;<br>&nbsp; end;<br>end;<br><br>exports run;<br><br>begin<br>&nbsp; //建立内存映象文件,用来保存全局变量<br>&nbsp; MemFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShared),HookMemFileName);<br>&nbsp; Shared:=MapViewOfFile(MemFile,FILE_MAP_WRITE,0,0,0);<br>&nbsp; DLLProc:=@DllEntryPoint;<br>end.<br><br>---------这是*.exe主程序---------------------------<br><br>Program WinHook;<br><br>uses windows,messages,sysutils;<br>{$r *.res} &nbsp;//使用资源文件<br>const<br>&nbsp; HTName:array[1..13] of pchar=(<br>&nbsp; 'CALLWNDPROC','CALLWNDPROCRET','CBT','DEBUG','GETMESSAGE','JOURNALPLAYBACK',<br>&nbsp; 'JOURNALRECORD','KEYBOARD','MOUSE','MSGFILTER','SHELL','SYSMSGFILTER','FOREGROUNDIDLE'<br>&nbsp; );<br>type<br>&nbsp; TWin = record<br>&nbsp; &nbsp; Msg:TMsg;<br>&nbsp; &nbsp; wClass:TWndClass;<br>&nbsp; &nbsp; hMain:integer;<br>&nbsp; &nbsp; hbut,hlab:array[1..16] of integer;<br>&nbsp; &nbsp; hLib:integer;<br>&nbsp; &nbsp; HookStat:array[1..16] of bool;<br>&nbsp; end;<br>var<br>&nbsp; Win:TWin; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//结构变量<br>&nbsp; wmhook:integer;<br>&nbsp; WorkPath:string;<br>&nbsp; hRun:procedure;stdcall;<br>//<br>procedure runhookfun;<br>begin<br>&nbsp; win.hlib:=loadlibrary(pchar(WorkPath+'DemoHook.dll'));<br>&nbsp; if win.hlib=0 then messagebox(win.hmain,'error','',0);<br>&nbsp; hrun:=GetProcAddress(win.hlib,'run');<br>&nbsp; if @hrun&lt;&gt;nil then hrun;<br>end;<br><br>procedure runhook;<br>var tid:integer;<br>begin<br>&nbsp; createthread(nil,0,@runhookfun,nil,0,tid);<br>end;<br><br>function WindowProc(hWnd,Msg,wParam,lParam:longint):LRESULT; stdcall;<br>var k:integer;<br>begin<br>&nbsp; case Msg of<br>&nbsp; WM_SYSCOMMAND:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; case wparam of<br>&nbsp; &nbsp; &nbsp; SC_CLOSE:<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if findwindow('WideHook','WideHook')&lt;&gt;0 then postmessage(findwindow('WideHook','WideHook'),wm_destroy,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;//showwindow(hwnd,sw_hide);<br>&nbsp; &nbsp; &nbsp; SC_MINIMIZE:;//showwindow(hwnd,sw_hide);<br>&nbsp; &nbsp; &nbsp; SC_MAXIMIZE:;<br>&nbsp; &nbsp; &nbsp; SC_DEFAULT:;<br>&nbsp; &nbsp; &nbsp; SC_MOVE:;<br>&nbsp; &nbsp; &nbsp; SC_SIZE:;<br>&nbsp; &nbsp; &nbsp; //else<br>&nbsp; &nbsp; &nbsp; //Result := DefWindowProc(hwnd, uMsg, wParam, lParam);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; wm_command:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; for k:=1 to 13 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if (lparam=win.hbut[k]) and ((k=6) or (k=7)) then break;<br>&nbsp; &nbsp; &nbsp; &nbsp; if lparam=win.hbut[k] then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if win.HookStat[k]=false then postmessage(findwindow('WideHook','WideHook'),wmhook,k,0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else postmessage(findwindow('WideHook','WideHook'),wmhook,-k,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; wm_destroy:<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; freelibrary(win.hlib);<br>&nbsp; &nbsp; &nbsp; halt;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; if msg=wmhook then<br>&nbsp; begin<br>&nbsp; &nbsp; if wparam&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; setwindowtext(win.hbut[wparam],pchar('stop'));<br>&nbsp; &nbsp; &nbsp; win.HookStat[wparam]:=true;<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; setwindowtext(win.hbut[-wparam],pchar('start'));<br>&nbsp; &nbsp; &nbsp; win.HookStat[-wparam]:=false;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; Result:=DefWindowProc(hWnd,Msg,wParam,lParam);<br>end;<br><br>//主程序的执行函数<br>procedure run;stdcall;<br>var k:integer;<br>begin<br>&nbsp; if findwindow('WinHook',nil)&lt;&gt;0 then exit;<br>&nbsp; win.wClass.hInstance:= &nbsp; &nbsp;hInstance;<br>&nbsp; with win.wclass do<br>&nbsp; begin<br>&nbsp; &nbsp; hIcon:= &nbsp; &nbsp; &nbsp; &nbsp;LoadIcon(hInstance,'MAINICON');<br>&nbsp; &nbsp; hCursor:= &nbsp; &nbsp; &nbsp;LoadCursor(0,IDC_ARROW);<br>&nbsp; &nbsp; hbrBackground:= COLOR_BTNFACE+1;<br>&nbsp; &nbsp; Style:= &nbsp; &nbsp; &nbsp; &nbsp;CS_PARENTDC;<br>&nbsp; &nbsp; lpfnWndProc:= &nbsp;@WindowProc;<br>&nbsp; &nbsp; lpszClassName:='WinHook';<br>&nbsp; end;<br>&nbsp; RegisterClass(win.wClass);<br>&nbsp; win.hmain:=CreateWindow(win.wClass.lpszClassName,'Delphi Hook Demo 2001',WS_VISIBLE or WS_OVERLAPPEDWINDOW,0,0,240,450,0,0,hInstance,nil);<br>&nbsp; for k:=1 to 13 do<br>&nbsp; begin<br>&nbsp; &nbsp; win.hbut[k]:=CreateWindow('BUTTON','Start',WS_VISIBLE or WS_CHILD,10,10+30*(k-1),50,24,win.hmain,0,hInstance,nil);<br>&nbsp; &nbsp; win.hlab[k]:=CreateWindow('STATIC',HTName[k],WS_VISIBLE or WS_CHILD,70,10+30*(k-1)+4,150,24,win.hmain,0,hInstance,nil);<br>&nbsp; &nbsp; win.HookStat[k]:=false;<br>&nbsp; end;<br>&nbsp; WorkPath:=ExtractFilePath(ParamStr(0));<br>&nbsp; runhook;<br>&nbsp; wmhook:=registerwindowmessage(pchar('wm_hook'));<br>&nbsp; while(GetMessage(win.Msg,win.hmain,0,0)) do<br>&nbsp; begin<br>&nbsp; &nbsp; TranslateMessage(win.Msg);<br>&nbsp; &nbsp; DispatchMessage(win.Msg);<br>&nbsp; end;<br>end;<br><br>begin<br>&nbsp; run; &nbsp;//开始运行主程序<br>end.<br>
 
下面的是jingtao的键盘钩子程序。<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,<br>&nbsp; StdCtrls, ExtCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; function Keyhookresult(lP: integer; wP: integer): pchar;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hookkey: string;<br>&nbsp; hooktimes: word;<br>&nbsp; hHook: integer;<br>implementation<br>{$R *.DFM}<br><br>function TForm1.Keyhookresult(lP: integer; wP: integer): pchar;<br>begin<br>&nbsp; result := '[Print Screen]';<br>&nbsp; case lp of<br>&nbsp; &nbsp; 10688: result := '`';<br>&nbsp; &nbsp; 561: Result := '1';<br>&nbsp; &nbsp; 818: result := '2';<br>&nbsp; &nbsp; 1075: result := '3';<br>&nbsp; &nbsp; 1332: result := '4';<br>&nbsp; &nbsp; 1589: result := '5';<br>&nbsp; &nbsp; 1846: result := '6';<br>&nbsp; &nbsp; 2103: result := '7';<br>&nbsp; &nbsp; 2360: result := '8';<br>&nbsp; &nbsp; 2617: result := '9';<br>&nbsp; &nbsp; 2864: result := '0';<br>&nbsp; &nbsp; 3261: result := '-';<br>&nbsp; &nbsp; 3515: result := '=';<br>&nbsp; &nbsp; 4177: result := 'Q';<br>&nbsp; &nbsp; 4439: result := 'W';<br>&nbsp; &nbsp; 4677: result := 'E';<br>&nbsp; &nbsp; 4946: result := 'R';<br>&nbsp; &nbsp; 5204: result := 'T';<br>&nbsp; &nbsp; 5465: result := 'Y';<br>&nbsp; &nbsp; 5717: result := 'U';<br>&nbsp; &nbsp; 5961: result := 'I';<br>&nbsp; &nbsp; 6223: result := 'O';<br>&nbsp; &nbsp; 6480: result := 'P';<br>&nbsp; &nbsp; 6875: result := '[';<br>&nbsp; &nbsp; 7133: result := ']';<br>&nbsp; &nbsp; 11228: result := '/';<br>&nbsp; &nbsp; 7745: result := 'A';<br>&nbsp; &nbsp; 8019: result := 'S';<br>&nbsp; &nbsp; 8260: result := 'D';<br>&nbsp; &nbsp; 8518: result := 'F';<br>&nbsp; &nbsp; 8775: result := 'G';<br>&nbsp; &nbsp; 9032: result := 'H';<br>&nbsp; &nbsp; 9290: result := 'J';<br>&nbsp; &nbsp; 9547: result := 'K';<br>&nbsp; &nbsp; 9804: result := 'L';<br>&nbsp; &nbsp; 10170: result := ';';<br>&nbsp; &nbsp; 10462: result := '''';<br>&nbsp; &nbsp; 11354: result := 'Z';<br>&nbsp; &nbsp; 11608: result := 'X';<br>&nbsp; &nbsp; 11843: result := 'C';<br>&nbsp; &nbsp; 12118: result := 'V';<br>&nbsp; &nbsp; 12354: result := 'B';<br>&nbsp; &nbsp; 12622: result := 'N';<br>&nbsp; &nbsp; 12877: result := 'M';<br>&nbsp; &nbsp; 13244: result := ',';<br>&nbsp; &nbsp; 13502: result := '.';<br>&nbsp; &nbsp; 13759: result := '/';<br>&nbsp; &nbsp; 13840: result := '[Right-Shift]';<br>&nbsp; &nbsp; 14624: result := '[Space]';<br>&nbsp; &nbsp; 283: result := '[Esc]';<br>&nbsp; &nbsp; 15216: result := '[F1]';<br>&nbsp; &nbsp; 15473: result := '[F2]';<br>&nbsp; &nbsp; 15730: result := '[F3]';<br>&nbsp; &nbsp; 15987: result := '[F4]';<br>&nbsp; &nbsp; 16244: result := '[F5]';<br>&nbsp; &nbsp; 16501: result := '[F6]';<br>&nbsp; &nbsp; 16758: result := '[F7]';<br>&nbsp; &nbsp; 17015: result := '[F8]';<br>&nbsp; &nbsp; 17272: result := '[F9]';<br>&nbsp; &nbsp; 17529: result := '[F10]';<br>&nbsp; &nbsp; 22394: result := '[F11]';<br>&nbsp; &nbsp; 22651: result := '[F12]';<br>&nbsp; &nbsp; 10768: Result := '[Left-Shift]';<br>&nbsp; &nbsp; 14868: result := '[CapsLock]';<br>&nbsp; &nbsp; 3592: result := '[Backspace]';<br>&nbsp; &nbsp; 3849: result := '[Tab]';<br>&nbsp; &nbsp; 7441:<br>&nbsp; &nbsp; &nbsp; if wp &gt; 30000 then<br>&nbsp; &nbsp; &nbsp; &nbsp; result := '[Right-Ctrl]'<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; result := '[Left-Ctrl]';<br>&nbsp; &nbsp; 13679: result := '[Num /]';<br>&nbsp; &nbsp; 17808: result := '[NumLock]';<br>&nbsp; &nbsp; 300: result := '[Print Screen]';<br>&nbsp; &nbsp; 18065: result := '[Scroll Lock]';<br>&nbsp; &nbsp; 17683: result := '[Pause]';<br>&nbsp; &nbsp; 21088: result := '[Num0]';<br>&nbsp; &nbsp; 21358: result := '[Num.]';<br>&nbsp; &nbsp; 20321: result := '[Num1]';<br>&nbsp; &nbsp; 20578: result := '[Num2]';<br>&nbsp; &nbsp; 20835: result := '[Num3]';<br>&nbsp; &nbsp; 19300: result := '[Num4]';<br>&nbsp; &nbsp; 19557: result := '[Num5]';<br>&nbsp; &nbsp; 19814: result := '[Num6]';<br>&nbsp; &nbsp; 18279: result := '[Num7]';<br>&nbsp; &nbsp; 18536: result := '[Num8]';<br>&nbsp; &nbsp; 18793: result := '[Num9]';<br>&nbsp; &nbsp; 19468: result := '[*5*]';<br>&nbsp; &nbsp; 14186: result := '[Num *]';<br>&nbsp; &nbsp; 19053: result := '[Num -]';<br>&nbsp; &nbsp; 20075: result := '[Num +]';<br>&nbsp; &nbsp; 21037: result := '[Insert]';<br>&nbsp; &nbsp; 21294: result := '[Delete]';<br>&nbsp; &nbsp; 18212: result := '[Home]';<br>&nbsp; &nbsp; 20259: result := '[End]';<br>&nbsp; &nbsp; 18721: result := '[PageUp]';<br>&nbsp; &nbsp; 20770: result := '[PageDown]';<br>&nbsp; &nbsp; 18470: result := '[UP]';<br>&nbsp; &nbsp; 20520: result := '[DOWN]';<br>&nbsp; &nbsp; 19237: result := '
';<br>&nbsp; &nbsp; 19751: result := '
';<br>&nbsp; &nbsp; 7181: result := '[Enter]';<br>&nbsp; end;<br>end;<br><br>function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;<br>begin<br>&nbsp; if (peventmsg(lparam)^.message = WM_KEYDOWN) then<br>&nbsp; &nbsp; hookkey := hookkey + Form1.Keyhookresult(peventMsg(lparam)^.paramL, peventmsg(lparam)^.paramH);<br>&nbsp; if length(hookkey) &gt; 30 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Form1.ListBox1.Items.Add(hookkey);<br>&nbsp; &nbsp; &nbsp; hookkey := TimeToStr(now) + ' &nbsp;';<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; hooktimes := 0;<br>&nbsp; hHook := 0;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; inc(hooktimes);<br>&nbsp; if hooktimes = 1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; hookkey := TimeToStr(now) + ' &nbsp;';<br>&nbsp; &nbsp; &nbsp; hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);<br>&nbsp; &nbsp; &nbsp; MessageBox(0, '&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;frac14;à&amp;Ecirc;&amp;Oacute;&amp;AElig;&amp;ocirc;&amp;para;&amp;macr;', '&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;', MB_ICONINFORMATION + MB_OK);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; UnHookWindowsHookEx(hHook);<br>&nbsp; hHook := 0;<br>&nbsp; if hooktimes &lt;&gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; MessageBox(0, '&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;frac14;à&amp;Ecirc;&amp;Oacute;&amp;sup1;&amp;Oslash;±&amp;Otilde;', '&amp;ETH;&amp;Aring;&amp;Iuml;&amp;cent;', MB_ICONINFORMATION + MB_OK);<br>&nbsp; &nbsp; end;<br>&nbsp; hooktimes := 0;<br>end;<br><br>end.<br>​
 
后退
顶部