注册系统热键

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.

以上是关于注册系统热键的主要内容,如果未能解决你的问题,请参考以下文章

RegisterHotKey注册热键,然后响应WM_HOTKEY消息

为啥按下热键组合时没有触发我的注册热键

MFC-注册热键

Windows热键注册的底层原理

qt 注册热键

qt 注册热键