type
THotKey = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
procedure HotKeyDown(var Msg:Tmessage);message WM_HOTKEY;
end;
var
HotKey: THotKey;
HotKeyID : Integer;
Alabel : TLabel;
implementation
{$R *.dfm}
procedure THotKey.HotKeyDown(var Msg:TMessage);
begin
if ( Msg.LParamLo = 0 ) and (Msg.LParamHi = VK_ESCAPE) then
begin
Alabel.Caption := '按下了 ESC 键 !';
end;
end;
procedure THotKey.FormCreate(Sender: TObject);
begin
HotKeyId := GlobalAddAtom('MyHotKey')-$C00;
RegisterHotKey(Handle,HotKeyID,0,VK_ESCAPE);
ALabel := TLabel.Create(nil);
ALabel.Parent := HotKey;
ALabel.Left := 10;
ALabel.Top := 10;
Alabel.Caption := '未按 ESC 键 !';
end;
procedure THotKey.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(handle,HotKeyid);
Alabel.Free;
end;