F
flash9
Unregistered / Unconfirmed
GUEST, unregistred user!
我测试到下面的代码在WINXP下,一旦用Ctrl+Alt+Del之后,hook就失效了,不能检测到键<br>盘和鼠标的重新动作。请问是哪里出了问题呢? <br><br>unit hook;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Timer1: TTimer;<br> Label1: TLabel;<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure Timer1Timer(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> hHook: integer;<br> Timesnum: integer;<br><br>implementation<br><br>{$R *.dfm}<br><br>const<br> Timescount = 10;<br><br>function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;<br>begin<br> Timesnum := 0;<br> Result := 0;<br>end;<br><br>function StartHook: Boolean;<br>begin<br> Result := False;<br> if hHook = 0 then<br> begin<br> hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);<br> if hHook > 0 then<br> begin<br> Result := True;<br> end;<br> end;<br>end;<br><br>procedure StopHook;<br>begin<br> if hHOok > 0 then<br> begin<br> UnHookWindowsHookEx(hHook);<br> hHook := 0;<br> end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> hHook := 0;<br> StartHook();<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> stophook;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> inc(Timesnum);<br> label1.Caption := floattostr(Timesnum);<br> if Timesnum >= Timescount then<br> ShowMessage('ok');<br>end;<br><br>end.<br>