高手来看看hook的问题:我用内存流保存hook 怎么键盘输入的会没有?错在那里了(100分)

M

myqq

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>&nbsp; &nbsp; ListBox1: TListBox;<br>procedure FormCreate(Sender: TObject);<br>procedure Button1Click(Sender: TObject);<br>procedure Button2Click(Sender: TObject);<br>procedure Button3Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button4Click(Sender: TObject);<br>private<br>{ Private declarations }<br>public<br>{ Public declarations }<br>end;<br><br>var<br>Form1: TForm1;<br><br>eventdata:Tmemorystream;<br>EventArr:array[0..1000]of EVENTMSG;<br>Event:EVENTMSG;<br>EventLog:Integer;<br>PlayLog:Integer;<br>hHook,hPlay:Integer;<br>recOK:Integer;<br>canPlay:Integer;<br>bDelay:Bool;<br>implementation<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 &lt; 0 then //±&amp;Oslash;&amp;ETH;&amp;euml;&amp;frac12;&amp;laquo;&amp;Iuml;&amp;ucirc;&amp;Iuml;&amp;cent;&amp;acute;&amp;laquo;&amp;micro;&amp;Yacute;&amp;micro;&amp;frac12;&amp;Iuml;&amp;ucirc;&amp;Iuml;&amp;cent;&amp;Aacute;&amp;acute;&amp;micro;&amp;Auml;&amp;Iuml;&amp;Acirc;&amp;Ograve;&amp;raquo;&amp;cedil;&amp;ouml;&amp;frac12;&amp;Oacute;&amp;Ecirc;&amp;Uuml;&amp;micro;&amp;yen;&amp;Ocirc;&amp;ordf;<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 begin<br>if bDelay then begin<br>bDelay:=False;<br>Result:=50;<br>end;<br>Eventdata.read(Event,sizeof(Event));<br><br>pEventMSG(lParam)^:=Event;<br>//pEventMSG(lParam)^:=EventArr[PlayLog];<br>end<br>else if ((canPlay = 1)and(iCode = HC_SKIP))then begin<br>bDelay := True;<br>PlayLog:=PlayLog+1;<br>end;<br>//if PlayLog&gt;=EventLog then begin<br>if eventdata.Position&gt;eventdata.size-1 then begin<br>UNHookWindowsHookEx(hPlay);<br>end;<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 &lt; 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&gt;0) and (iCode = HC_ACTION)) then begin<br>EventArr[EventLog]:=pEventMSG(lParam)^;<br>Event:=EventArr[EventLog];<br>form1.caption:=inttostr(sizeof(Event));<br>Eventdata.write(Event,sizeof(Event));<br>EventLog:=EventLog+1;<br><br>if EventLog&gt;=1000 then begin<br>UnHookWindowsHookEx(hHook);<br>end;<br>end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>eventdata:=Tmemorystream.create;<br>Button1.Caption:='&amp;frac14;&amp;Iacute;&amp;Acirc;&amp;frac14;';<br>Button2.Caption:='&amp;Iacute;&amp;pound;&amp;Ouml;&amp;sup1;';<br>Button3.Caption:='&amp;raquo;&amp;Oslash;·&amp;Aring;';<br>Button4.Caption:='±&amp;pound;&amp;acute;&amp;aelig;';<br>Button2.Enabled:=False;<br>Button3.Enabled:=False;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>EventLog:=0;<br>eventdata.Clear;<br>eventdata.Seek(0,soFromBeginning);<br>//&amp;frac12;¨&amp;Aacute;&amp;cent;&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;Ecirc;ó±ê&amp;sup2;&amp;Ugrave;×÷&amp;Iuml;&amp;ucirc;&amp;Iuml;&amp;cent;&amp;frac14;&amp;Iacute;&amp;Acirc;&amp;frac14;&amp;Aacute;&amp;acute;<br>hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);<br>//eventdata.write('End',20);<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><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>eventdata.Seek(0,soFromBeginning);<br>//&amp;frac12;¨&amp;Aacute;&amp;cent;&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;Ecirc;ó±ê&amp;sup2;&amp;Ugrave;×÷&amp;Iuml;&amp;ucirc;&amp;Iuml;&amp;cent;&amp;frac14;&amp;Iacute;&amp;Acirc;&amp;frac14;&amp;raquo;&amp;Oslash;·&amp;Aring;&amp;Aacute;&amp;acute;<br>hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,<br>HInstance,0);<br><br>//Button3.Enabled:=False;<br>end;<br><br>procedure TForm1.Button4Click(Sender: TObject);<br>begin<br>eventdata.SaveToFile('c:/data.1');<br>//EventArr[PlayLog];<br>end;<br><br>end.<br>
 
顶部