我一直在嘗試註冊3個熱鍵。 我跟着this的例子(或this)。無法註冊多個全局熱鍵
如果我註冊一個熱鍵,代碼正在工作。 但是,如果我嘗試註冊3個熱鍵,只有最後一個登記的工作:
procedure TFrmSettings.FormCreate;
begin
atomN:= GlobalAddAtom(pchar('atomN'));
atomT:= GlobalAddAtom(pchar('atomT'));
atomH:= GlobalAddAtom(pchar('atomH'));
end;
procedure TFrmSettings.test1;
begin
RegisterHotShortCut(Handle, atomN, hotN.HotKey); // first registered
RegisterHotShortCut(Handle, atomH, hotH.HotKey); // second registered
RegisterHotShortCut(Handle, atomT, hotT.HotKey); // third - only this works
end;
RegisterHotShortCut在網頁中宣佈上述。
function RegisterHotShortCut(const h:THandle; const Atom: integer; const ShortCut: TShortCut): Boolean;
VAR
key : Word;
Shift: TShiftState;
begin
Windows.UnregisterHotKey(h, Atom);
ShortCutToKey(ShortCut, key, shift);
Result:= RegisterHotKey(h, Atom, ShiftState2Modifier(Shift), key);
end;
如果在上面的代碼中,我評論最後一行,那麼上一個熱鍵(hotH)正在工作。這意味着我宣佈一切正常,但最後一個熱鍵控制了(取消註冊)其他熱鍵。
或者用其他方式說出來,按第一個註冊快捷方式的組合鍵不會使程序輸入TFrmSettings.HotyKeyMsg(VAR msg: TMessage)
過程。
任何提示? 謝謝。
EDIT1:
有跡象表明,似乎對其他工作,簡單的代碼片段,但我真的需要讓用戶更改快捷方式,所以我需要的ShortCutToKey程序。
我應該爲每個全局快捷方式聲明一個原子。對?
EDIT2: 解決 上面的代碼失敗,只有當我使用 「GlobalAddAtom」 功能。如果我不使用原子,而只使用數字1,2和3,那麼代碼就可以工作。如果我使用4,5,6,代碼將再次失敗。 問題(半)解決。
嗨。 RegisterHotShortCut在上面提到的網頁中聲明。 – Ampere 2009-04-13 11:17:56
糟糕,是的,你是正確的,我看到你現在已經把它包含在問題中了。恐怕我不能進一步幫助。 – hlovdal 2009-04-13 11:51:11
無論如何感謝您的幫助。 – Ampere 2009-04-13 11:58:04