我有一个线程执行某些事情,最后它应该将我的 F 键绑定为全局热键,我无法让它工作,任何关于我做错了什么的见解或者如果 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 );
}
编辑:当然我不会同时绑定这两个,一个总是被注释掉。