如何在程序中定义两个系统全局快捷键,一个为Ctrl+Shift+Z,另一个为Shift+Enter,并且无论当按Ctrl+Shift+Z时,还是按Shift+Enter时,都能正确执行他们事先定义好的代码动作。

解决方案 »

  1.   

    RegisterHotKey 应该只有这个方法了吧。学习
      

  2.   

      //注册系统热键 CTRL+M
      HotKeyId := GlobalAddAtom('show') - $C000;
      RegisterHotKey(Self.Handle, hotkeyid, MOD_CONTROL, 77);  //注册系统热键F7
      HotKeyId1 := GlobalAddAtom('next') - $C000;
      RegisterHotKey(Self.Handle, hotkeyid1, 0, VK_F7);  //在程序最后释放系统热键
      UnRegisterHotKey(self.handle, HotKeyId);
      UnRegisterHotKey(self.handle, HotKeyId1);
      DeleteAtom(hotKeyID);
      DeleteAtom(hotKeyID1);
      注:RegisterHotKey为注册热键函数,UnRegisterHotKey为热键释放函数,GlobalAddAtom为全局原子表添加唯一原子 
      

  3.   

    定义函数接收热键     
    procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;procedure TForm1.HotKeyDown(var Msg: Tmessage);
    begin
      if (Msg.LparamLo = MOD_CONTROL) and (Msg.LParamHi = 77) or (msg.LParamHi = vk_F7) then // 假设热键为CTRL+M
      begin
        ... ...
      end;
    end;