注册系统热键
Posted tobetterlife
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了注册系统热键相关的知识,希望对你有一定的参考价值。
unit unitFrmMain; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } hotkeyid: integer; procedure WMhotkeyhandle(var msg: Tmessage); message WM_HOTKEY; //响应热键消息 public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin hotkeyid := GlobalAddAtom(pchar (‘UserDefineHotKey‘)) - $C000; //减去$C000是为了保证取值范围的限制 registerhotkey(handle, hotkeyid, MOD_ALT or MOD_CONTROL, $42);//热键为ctrl+Alt+B end; procedure TForm1.WMhotkeyhandle(var msg: Tmessage); begin if (msg.LParamHi = $42) and (msg.lparamLo = MOD_CONTROL or mod_Alt) then begin msg.Result := 1; //该消息已经处理 application.BringToFront; ShowMessage(‘你已经按下热键‘) end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin unregisterhotkey(handle, hotkeyid); DeleteAtom(HotKeyID); end; end.
以上是关于注册系统热键的主要内容,如果未能解决你的问题,请参考以下文章