我有一个线程正在执行某些事情,最后它应该将我的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 );
}
编辑:当然,我不会同时约束这两个,一个总是被注释掉。
答案 0 :(得分:2)