Demo下载:https://git.oschina.net/xieyimo9/quanjurejian.git
- 主要代码:
-
procedure TForm1.HotKey(var msg: TMessage); begin if msg.WParam =FHotKeyId_Alt_Down then Memo1.Lines.Add(‘Alt Down‘) else if msg.WParam =FHotKeyId_Alt_Up then Memo1.Lines.Add(‘Alt Up‘) else if msg.WParam =FHotKeyId_Ctrl_F12 then Memo1.Lines.Add(‘Ctrl + F12‘); end; procedure TForm1.FormCreate(Sender: TObject); begin FHotKeyId_Alt_Down := GlobalAddAtom(‘MyHotKey_Alt_Down‘); { 全局热键ID } RegisterHotKey(Self.Handle, FHotKeyId_Alt_Down, MOD_ALT, VK_MENU); { 注册全局热键 Alt Down } FHotKeyId_Alt_Up := GlobalAddAtom(‘MyHotKey_Alt_Up‘); { 全局热键ID } RegisterHotKey(Self.Handle, FHotKeyId_Alt_Up, MOD_ALT, 0); { 注册全局热键 Alt Up } FHotKeyId_Ctrl_F12 := GlobalAddAtom(‘MyHotKeyCtrl_F12‘); { 全局热键ID } RegisterHotKey(Self.Handle, FHotKeyId_Ctrl_F12, MOD_CONTROL, VK_F12); { 注册全局热键 Ctrl + F12 } end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin UnregisterHotKey(Handle, FHotKeyId_Alt_Down); { 反注册全局热键 } GlobalDeleteAtom(FHotKeyId_Alt_Down); UnregisterHotKey(Handle, FHotKeyId_Alt_Up); { 反注册全局热键 } GlobalDeleteAtom(FHotKeyId_Alt_Up); UnregisterHotKey(Handle, FHotKeyId_Ctrl_F12); { 反注册全局热键 } GlobalDeleteAtom(FHotKeyId_Ctrl_F12); end;
全局热键
时间: 2024-10-12 11:53:46