大家帮忙研究一下,如何将日志钩子记录下的动作全部保存到文件中,程序下次运行时打开此文件仍然可以重放上一次录制的东西?(100分)

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

yu98041154

Unregistered / Unconfirmed
GUEST, unregistred user!
如题<br>目前的代码如下,但是没有实现将动作保存到文件中和从文件中读取并回放的步骤。<br>谢谢各位大侠...<br>----------------------------------------------------------------------------------<br><br>unit Unit1;<br>interface<br> uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; <br>type TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Button3: TButton;<br> Edit1: TEdit;<br> Button4: TButton;<br> &nbsp; &nbsp;Memo1: TMemo;<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> var<br> Form1: TForm1;<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> {$R *.DFM}<br> Function PlayProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br> begin <br> canPlay:=1;<br> Result:=0;<br> if iCode &lt; 0 then //必须将消息传递到消息链的下一个接受单元<br> &nbsp; &nbsp;Result := CallNextHookEx(hPlay,iCode,wParam,lParam)<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;if iCode = HC_SYSMODALON then canPlay:=0<br> &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; if iCode = HC_SYSMODALOFF then canPlay:=1<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((canPlay =1 )and(iCode=HC_GETNEXT)) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if bDelay then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bDelay:=False;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result:=50;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pEventMSG(lParam)^:=EventArr[PlayLog];<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ((canPlay = 1)and(iCode = HC_SKIP))then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bDelay := True;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PlayLog:=PlayLog+1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;if PlayLog&gt;=EventLog then<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; UNHookWindowsHookEx(hPlay);<br> &nbsp; &nbsp; &nbsp; end;<br>end;<br> function HookProc (iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br> begin<br> recOK:=1;<br> Result:=0;<br> if iCode &lt; 0 then<br> &nbsp; &nbsp;Result := CallNextHookEx(hHook,iCode,wParam,lParam)<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;if iCode = HC_SYSMODALON then<br> &nbsp; &nbsp; &nbsp; recOK:=0<br> &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; if iCode = HC_SYSMODALOFF then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; recOK:=1<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((recOK&gt;0) and (iCode = HC_ACTION)) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventArr[EventLog]:=pEventMSG(lParam)^;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventLog:=EventLog+1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if EventLog&gt;=1000 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UnHookWindowsHookEx(hHook);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> end;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp; Button1.Caption:='纪录';<br> &nbsp; Button2.Caption:='停止';<br> &nbsp; Button3.Caption:='回放';<br> &nbsp; Button4.Caption:='范例';<br> &nbsp; Button2.Enabled:=False;<br> &nbsp; Button3.Enabled:=False;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>EventLog:=0; //建立键盘鼠标操作消息纪录链<br>hHook:=SetwindowsHookEx (WH_JOURNALRECORD,HookProc,HInstance,0);<br>Button2.Enabled:=True;<br>Button1.Enabled:=False;<br>end; <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>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br> PlayLog:=0; //建立键盘鼠标操作消息纪录回放链<br> hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc, HInstance,0);<br> Button3.Enabled:=False;<br> end;<br> end.
 
不明白,你不是都记录下来了么,怎么保存不了?能保存为啥不能读出来回放?
 
不好意思,没说明白,想保存在硬盘上,下次读出来回放
 
以前的贴子里有,你搜一下,我以前看着过
 
后退
顶部