我想做个简单的热键程序,可以在界面中设置 Modifier 键。
我做为 CheckBox的 ctrl, alt, shift, win...
当用户点击button时,我这样设置值:
但提示出错:Incompatible types: 'Cardinal' and 'procedure, untyped pointer or untyped parameter'
//直接设置也不行请指点小弟,谢谢!    RegisterHotKey(AppQuickStart.Handle, id,
          if _ctrl then
            getModifier('ctrl');
          if _alt then
            getModifier('alt');
          if _shift then
            getModifier('shift');
          if _win then
            getModifier('win');
    , _key);//getModifier方法
function getModifier(modifier : String): UInt
begin
  if modifier = 'ctrl' then
    Return := MOD_CONTROL
  else if modifier = 'alt'
    Return := MOD_ALT
  else if modifier = 'shift'
    Return := MOD_SHIFT
  else if modifier = 'win'
    Return := MOD_WIN
end;

解决方案 »

  1.   

    我用HotKeyManager1控件
    procedure TFrmMain.HotkeyInit;
    var
      TempIni: TIniFile;
    begin
      //初始化热键
      TempIni := TIniFile.Create(extractfilepath(ParamStr(0))+'sys.ini');
      HotKeyVar1 :=TextToHotKey(TempIni.ReadString('Hotkey', 'HotkeyStr1', ''), LOCALIZED_KEYNAMES);
      HotKeyVar2 :=TextToHotKey(TempIni.ReadString('Hotkey', 'HotkeyStr2', ''), LOCALIZED_KEYNAMES);
      HotKeyVar3 :=TextToHotKey(tempIni.ReadString('Hotkey', 'HotkeyStr3', ''), LOCALIZED_KEYNAMES);
      HotKeyVar4 :=TextToHotKey(TempIni.ReadString('Hotkey', 'HotkeyStr4', ''), LOCALIZED_KEYNAMES);
      HotKeyVar5 :=TextToHotKey(TempIni.ReadString('Hotkey', 'HotkeyStr5', ''), LOCALIZED_KEYNAMES);
      if StrToBool(GetIniValue('Hotkey','Enable1')) then
      HotKeyVar1 :=HotKeyManager1.AddHotKey(HotKeyVar1);
      if StrToBool(GetIniValue('Hotkey','Enable2')) then
      HotKeyVar2 :=HotKeyManager1.AddHotKey(HotKeyVar2);
      if StrToBool(GetIniValue('Hotkey','Enable3')) then
      HotKeyVar3 :=HotKeyManager1.AddHotKey(HotKeyVar3);
      if StrToBool(GetIniValue('Hotkey','Enable4')) then
      HotKeyVar4 :=HotKeyManager1.AddHotKey(HotKeyVar4);
      if StrToBool(GetIniValue('Hotkey','Enable5')) then
      HotKeyVar5 :=HotKeyManager1.AddHotKey(HotKeyVar5);
    end;