[英]RegisterHotkey only working in WIndows 7, not in XP, server 2003
I am setting up global shortcut keys in Windows, using the RegisterHotKey method我在 Windows 中设置全局快捷键,使用 RegisterHotKey 方法
public static int MOD_CONTROL = 0x2;
public static int WM_HOTKEY = 0x312;
RegisterHotKey(this.Handle, 0, MOD_CONTROL | MOD_NOREPEAT, 96);
// ctrl numpad0
The code to process this is:处理这个的代码是:
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_HOTKEY)
{
MessageBox.Show("a hotkey is pressed"); //this also only shows in win7
if (m.WParam.ToInt32() == 0) //ctrl numpad0
{
MessageBox.Show("Hotkey ctrl numpad0 pressed");
// works fine in win7
}
}
base.WndProc(ref m);
}
On my windows 7 PC this works, but in XP or Windows Server 2003 it does not.在我的 windows 7 PC 上,这是可行的,但在 XP 或 Windows Server 2003 上却不行。 Any ideas where it goes wrong?
有什么想法会出错吗?
Looking at the documentation for RegisterHotKey it states that the MOD_NOREPEAT flag is not supported on Vista/XP/2K.查看RegisterHotKey的文档,它指出 Vista/XP/2K 不支持 MOD_NOREPEAT 标志。 I suspect that this is your problem.
我怀疑这是你的问题。
You should check the return value which would tell you immediately that something is wrong.您应该检查返回值,它会立即告诉您有问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.