注册热键(20分)

  • 主题发起人 你若有情
  • 开始时间

你若有情

Unregistered / Unconfirmed
GUEST, unregistred user!
我想注册一个"全局热键",当在任何窗口中按下"F9"就执行sndPlaySound(s,0)函数.怎么样注册这个热键呢.
用RegisterHotKey函数吗?该怎么写
 
设置全局快捷键

CoDelphi.com
 摘 要:我需要系统范围内的快捷键,如何才能做到呢?
 关键字:快捷键
 类 别:系统控制
--------------------------------------------------------------------------------
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
protected
procedure hotykey(var msg:TMessage);
message WM_HOTKEY;
end;

var
Form1: TForm1;
id,id2:Integer;

implementation
{$R *.DFM}

procedure TForm1.hotykey(var msg:TMessage);
begin

if (msg.LParamLo=MOD_CONTROL) and (msg.LParamHi=81) then

begin

ShowMessage('Ctrl + Q ');
end;

if (msg.LParamLo=MOD_CONTROL) and (msg.LParamHi=82) then

begin

ShowMessage('Ctrl + R ');
end;

end;


procedure TForm1.FormCreate(Sender: TObject);
begin

id:=GlobalAddAtom('hotkey');
RegisterHotKey(handle,id,mod_control,81);

id2:=GlobalAddAtom('hotkey2');
RegisterHotKey(handle,id2,mod_control,82);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin

UnRegisterHotKey(handle,id);
UnRegisterHotKey(handle,id2);
end;
 
大哥,我是说只注册热键只需按一个按钮"F9"我要的不是组合键。
 
这样可以的.试试.
unit Unit1globaladdatom;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure HotKeyProc(Var msg:TWMHotKey);message WM_HotKey;
public
{ Public declarations }
end;

var
Form1: TForm1;
HotKey1:word;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
HotKey1:=GlobalAddAtom('nnss');
RegisterHotKey(handle,HotKey1,0,VK_F9);
//热键是F9
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,HotKey1)
end;

procedure TForm1.HotKeyProc(var msg: TWMHotKey);
begin
showmessage('hi');
end;

end.
 
谢谢二位,欢迎加我为好友
QQ:165113282
 

Similar threads

回复
0
查看
853
不得闲
S
回复
0
查看
763
SUNSTONE的Delphi笔记
S
S
回复
0
查看
643
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部