M
micony
Unregistered / Unconfirmed
GUEST, unregistred user!
真搞笑,这样一个小小的钩子程序,也有问题,
unit Hook;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hHook:integer;
implementation
{$R *.DFM}
function rPro(iCode:integer;wParam:wParam;lParam:lParam):LResult;stdcall;
var EvnMsg:TEventMsg;
begin
EvnMsg:=PEventMsg(lParam)^;
if EvnMsg.message=WM_KEYDOWN then
begin
if EvnMsg.paramL=20520 then //‘↓’键被按下
showmessage('↓');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hHook:=SetWindowsHookEx(WH_JOURNALRECORD,rPro,HInstance,0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnhookWindowsHookEx(hHook);
end;
end.
程序运行后,单击Button1,当按在“↓”键后,那个showmessage('↓')对话筐就老是弹出
哪怕放掉“↓”键,还是一样,为什么呢?真想不通。理论上只有“↓”键按下就弹出,
放开时就不应弹出了啊。为什么呢?谁能说原因呢?100分伺候:)
unit Hook;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
hHook:integer;
implementation
{$R *.DFM}
function rPro(iCode:integer;wParam:wParam;lParam:lParam):LResult;stdcall;
var EvnMsg:TEventMsg;
begin
EvnMsg:=PEventMsg(lParam)^;
if EvnMsg.message=WM_KEYDOWN then
begin
if EvnMsg.paramL=20520 then //‘↓’键被按下
showmessage('↓');
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hHook:=SetWindowsHookEx(WH_JOURNALRECORD,rPro,HInstance,0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnhookWindowsHookEx(hHook);
end;
end.
程序运行后,单击Button1,当按在“↓”键后,那个showmessage('↓')对话筐就老是弹出
哪怕放掉“↓”键,还是一样,为什么呢?真想不通。理论上只有“↓”键按下就弹出,
放开时就不应弹出了啊。为什么呢?谁能说原因呢?100分伺候:)