RegisterHotKey注册全局热键注册全局热键

//RegisterHotKey注册全局热键注册全局热键 

private
     { Private declarations }
     procedure HotKeyDown( var Msg: Tmessage); message WM_HOTKEY;
{
var
  Form1: TForm1; }

 HotKeyId:Integer; //声明变量

procedure TForm1.HotKeyDown( var Msg: Tmessage);
begin
   if (Msg.LparamLo = mod_alt) and (Msg.LParamHi = vk_F3) then
   begin
     if ShowWindow(Self.Handle,SW_SHOW) then ShowWindow(Self.Handle,SW_HIDE) //隐藏自身窗体
     else ShowWindow(Self.Handle,SW_SHOW) ; //显示自身窗体
   end;
end

procedure TForm1.FormCreate(Sender: TObject);
begin
    HotKeyId := GlobalAddAtom( 'MyHotKey') - $C000;
    RegisterHotKey(Self.Handle, HotKeyId, MOD_ALT, VK_F3); //
     {如果想注册其他热键可以在这里继续注册热键}
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    UnRegisterHotKey(Self.Handle, HotKeyId); //注销HotKey, 释放资源。
    DeleteAtom(HotKeyId);
end;




你可能感兴趣的:(key)