0
我有一個線程執行某些事情,並在最後它應該綁定我的F鍵作爲全局熱鍵,我一直無法得到這個工作,任何洞察力,我做錯了或如果RegisterHotKey是不是我的線程運行的原因?RegisterHotKey不工作一個單獨的線程?
[DllImport("user32.dll", SetLastError = true)]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, System.Windows.Input.ModifierKeys fsModifiers, Keys vk);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int WmHotKey = 0x0312;
private void onLoad()
{
//RegisterHotKey(this.Handle, 0, System.Windows.Input.ModifierKeys.None, Keys.F); // This works
}
private void OnSeparateThread()
{
// This gets called by a separate thread, in the full version of the code more stuff
// happen here, which does get executed.
RegisterHotKey(this.Handle, 0, System.Windows.Input.ModifierKeys.None, Keys.F); // Does not bind
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WmHotKey)
{
MessageBox.Show("Test me!");
}
base.WndProc(ref m);
}
編輯:當然,我不是同時綁定這兩個,一個總是被註釋掉。
文檔不只是裝飾。 [RegisterHotKey](http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309(v = vs.85).aspx):「此函數不能將熱鍵與由另一個窗口創建的窗口關聯線。」 –
似乎我錯過了:)謝謝。 –