用hook,肯定好用。public
procedure HandleMsg(var Msg:TMessage);message WM_HOTKEY;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
showmessage('ok!')
end;procedure TForm1.HandleMsg(var Msg: TMessage);
begin
speedbutton1.click;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle,$1000,MOD_CONTROL,VK_RETURN);//ctrl+return
end;自己改改好了。
procedure HandleMsg(var Msg:TMessage);message WM_HOTKEY;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
showmessage('ok!')
end;procedure TForm1.HandleMsg(var Msg: TMessage);
begin
speedbutton1.click;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle,$1000,MOD_CONTROL,VK_RETURN);//ctrl+return
end;自己改改好了。
//把它改成DLL就可以钩所有的窗口了。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hHook: Integer;implementation{$R *.dfm}function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
var
m:String;
begin
Result:=0;
//不是属于自己的消息,传给下一个钩子
if iCode < 0 then
Result := CallNextHookEx(hHook,iCode,wParam,lParam);
//判断是否按下右键
if wParam = WM_LBUTTONDOWN then
begin
m:='Left Button Clicked!';
Form1.ListBox1.Items.Add(m);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//建立鼠标操作消息钩子
hHook:=SetwindowsHookEx(WH_MOUSE ,HookProc,HInstance,0);
end;end.