delphi为程序添加系统级快捷键

若只是添加全局快捷键,只需要在form的keypress中添加监控代码即可.

var Form1: TForm1;

HotKeyId: Integer;

Implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

HotKeyid:=GlobalAddAtom('MyHotKey')-$C00;

RegisterHotKey(Handle, hotkeyid,MOD_ALT, VK_F8);

end;

procedure TForm1.HotKeyDown(var Msg: Tmessage);

begin

if (Msg.LparamLo = MOD_ALT) AND (Msg.LParamHi = VK_F8 )then begin

ShowMessage('F8');

end; end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

begin

UnRegisterHotKey(handle, HotKeyId);

end;

posted @ 2015-12-22 10:18  burningsky  阅读(166)  评论(0编辑  收藏  举报