unit Unit1;
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);
procedure HotKeyDown(var Msg: Tmessage);
message WM_HOTKEY;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
HotKeyId:Integer;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
HotKeyId:=GlobalAddAtom('MyHotKey')-$C000;
//注: HotKeyId的合法取之范围是0x0000到0xBFFF之间, GlobalAddAtom函数得到的值
//在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。
RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F8);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
UnRegisterHotKey(handle, HotKeyId);
end;
procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
if (Msg.LparamLo = MOD_ALT) AND (Msg.LParamHi = VK_F8) then
// 假设热键为ALT+F8
begin
showmessage('aaa');
end;
end;
end.
一个列程