S
seeyouknowme
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br>Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>StdCtrls;<br><br>type<br>TForm1 = class(TForm)<br>Button1: TButton;<br>Button2: TButton;<br>Button3: TButton;<br>Edit1: TEdit;<br>Button4: TButton;<br>procedure FormCreate(Sender: TObject);<br>procedure Button1Click(Sender: TObject);<br>procedure Button2Click(Sender: TObject);<br>procedure Button3Click(Sender: TObject);<br>private<br>{ Private declarations }<br>public<br>{ Public declarations }<br>end;<br><br>var<br>Form1: TForm1;<br><br>EventArr:array[0..1000]of EVENTMSG;<br>EventLog:Integer;<br>PlayLog:Integer;<br>hHook,hPlay:Integer;<br>recOK:Integer;<br>canPlay:Integer;<br>bDelay:Bool;<br>implementation<br>{typedef struct tagEVENTMSG { // em <br> UINT message;<br> UINT paramL;<br> UINT paramH;<br> DWORD time;<br> HWND hwnd;<br>}// EVENTMSG;}<br><br>{$R *.DFM}<br>Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>canPlay:=1;<br>Result:=0;<br><br>if iCode < 0 then //必须将消息传递到消息链的下一个接受单元<br> Result := CallNextHookEx(hPlay,iCode,wParam,lParam)<br>else if iCode = HC_SYSMODALON then<br> canPlay:=0<br>else if iCode = HC_SYSMODALOFF then<br> canPlay:=1<br>else if ((canPlay =1 )and(iCode=HC_GETNEXT)) then<br> begin<br> if bDelay then<br> begin<br> bDelay:=False;<br> Result:=50;<br> end;<br> pEventMSG(lParam)^:=EventArr[PlayLog];<br> end<br>else if ((canPlay = 1)and(iCode = HC_SKIP))then<br> begin<br> bDelay := True;<br> PlayLog:=PlayLog+1;<br> end;<br>if PlayLog>=EventLog then<br><br> UNHookWindowsHookEx(hPlay);<br><br>end;<br><br>function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br> recOK:=1;<br> Result:=0;<br><br> if iCode < 0 then<br> Result := CallNextHookEx(hHook,iCode,wParam,lParam) //执行当前钩子,<br> else if iCode = HC_SYSMODALON then<br> recOK:=0<br> else if iCode = HC_SYSMODALOFF then<br> recOK:=1<br> else if ((recOK>0) and (iCode = HC_ACTION)) then<br> begin<br> EventArr[EventLog]:=pEventMSG(lParam)^;<br> EventLog:=EventLog+1;<br> if EventLog >=1000 then<br> begin<br> UnHookWindowsHookEx(hHook);<br> end;<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> Button1.Caption:='纪录';<br> Button2.Caption:='停止';<br> Button3.Caption:='回放';<br> Button4.Caption:='范例';<br> //Button2.Enabled:=False;<br> //Button3.Enabled:=False;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> EventLog:=0;<br> //建立键盘鼠标操作消息纪录链<br> hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);<br> Button2.Enabled:=True;<br> Button1.Enabled:=False;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> UnHookWindowsHookEx(hHook); //停止 释放钩子<br> hHook:=0; //<br> Button1.Enabled:=True;<br> Button2.Enabled:=False;<br> Button3.Enabled:=True;<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>PlayLog:=0;<br>//建立键盘鼠标操作消息纪录回放链<br>hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,HInstance,0);<br>Button3.Enabled:=False;<br>{HHOOK SetWindowsHookEx(<br><br> int idHook, // type of hook to install 钩子类型 比如这里的WH_journalplayback,就是回放存储的信息过程<br> HOOKPROC lpfn, // address of hook procedure 钩子处理过程,hookProc 是一个回调过程,需要自己写,这里是指playpro过程<br> HINSTANCE hMod, // handle of application instance 实例句柄。DefHookProc<br> DWORD dwThreadId // identity of thread to install hook for<br> }<br>end;<br><br>end.<br>