1.在窗啟動時建立atom;(aatom:atom;定義在private中)
1if findatom('
zwxhotkey
')=0
then
2begin
3 aatom:=globaladdatom('
zwxhotkey');
4end;5
if registerhotkey(handle,aatom,mod_alt,$41) then
6begin
7 messagebox(handle,'
按alt+a
','提示
',mb_ok);
8end;
2.定義處理熱鍵的訊息過程(定義在private中,下面二個處理訊息的過程是一樣的)
1procedure hotkey(var msg:tmessage);message wm_hotkey;//
定義全域性熱鍵訊息事件2//
procedure hotkey2(var msg:twmhotkey);message wm_hotkey;//同上
3.訊息過程的處理(下面二個if任選乙個即可,如果msg在步驟2定義成twmhotkey,則不用轉換)
1procedure tform2.hotkey(var
msg: tmessage); 2
begin
3if twmhotkey(msg).hotkey=aatom then
4begin5//
showmessage('s');
6end;
7if (msg.lparamhi=$41) and (msg.lparamlo=mod_alt) then
8begin
//處理事情
13end;14
end;
4.程式關閉時,刪除熱鍵和原子
1procedure tform2.formclose(sender: tobject; var
action: tcloseaction);
2begin
3unregisterhotkey(handle,aatom);
4globaldeleteatom(aatom);
5end;
Delphi 全域性熱鍵註冊 使用
rad studio 10.2.3 測試 全域性變數 var mhotkey01,mhotkey02 integer 1 在程式建立的時候或者窗體顯示的時候註冊熱鍵 begin 原子 mhotkey01 mhotkey01 globaladdatom xiaoyin hotkey ctrl f1 c...
C 註冊全域性熱鍵的方法
在form裡加入以下 即可 protected override void wndproc ref message m base.wndproc ref m public void sethotkey keys c,bool bctrl,bool bshift,bool balt,bool bwin...
delphi程式熱鍵
要定義乙個全域性熱鍵,通常有三個步驟 1 定義windows的訊息wm hotkey的hook鏈,即 procedure myshortcut var message tmessage message wm hotkey 2 向windows加入乙個全域性原子hotkey globaladdatom...