Delphi7怎么样设置按钮快捷键?让程序运行以后随便在什么窗口都能使用快捷键点击按钮 20
unitUnit1;interfaceusesWindows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dial...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, clipbrd, Buttons, AppEvnts;
type
TForm1 = class(TForm)
Timer1: TTimer;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//模拟按住回车键并且鼠标双击
keybd_event(27, MapVirtualKey(27, 0), 0, 0);
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
timer1.Enabled:= False
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
timer1.Enabled:= True
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_F1: BitBtn2Click(nil);
VK_F2: BitBtn1Click(nil);
end;
end;
end.
上面的源代码运行以后只能当程序处于最前的时候才能用快捷键F1和F2
请问该如何写才能在所有的窗口都能使用这个程序的快捷键F1和F2?
能不能给出具体的代码?或者把源码发送到904935780@qq.com 展开
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, clipbrd, Buttons, AppEvnts;
type
TForm1 = class(TForm)
Timer1: TTimer;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//模拟按住回车键并且鼠标双击
keybd_event(27, MapVirtualKey(27, 0), 0, 0);
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
timer1.Enabled:= False
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
timer1.Enabled:= True
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_F1: BitBtn2Click(nil);
VK_F2: BitBtn1Click(nil);
end;
end;
end.
上面的源代码运行以后只能当程序处于最前的时候才能用快捷键F1和F2
请问该如何写才能在所有的窗口都能使用这个程序的快捷键F1和F2?
能不能给出具体的代码?或者把源码发送到904935780@qq.com 展开
3个回答
展开全部
键盘钩子。
写一个函数,注入进去。不过你要在什么地方都能用,这得是一个全局钩子。占资源。
如何写钩子参看下这里http://tangfeng.javaeye.com/blog/92407
不过这是mfc的。delphi差不多。
写一个函数,注入进去。不过你要在什么地方都能用,这得是一个全局钩子。占资源。
如何写钩子参看下这里http://tangfeng.javaeye.com/blog/92407
不过这是mfc的。delphi差不多。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询