我正在使用 RegisterHotKey 方法在 Windows 中设置全局快捷键
public static int MOD_CONTROL = 0x2;
public static int WM_HOTKEY = 0x312;
RegisterHotKey(this.Handle, 0, MOD_CONTROL | MOD_NOREPEAT, 96);
// ctrl numpad0
处理这个的代码是:
[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);
}
在我的 Windows 7 PC 上这有效,但在 XP 或 Windows Server 2003 中它不起作用。 有什么地方出了问题吗?
最佳答案
查看 RegisterHotKey 的文档它声明 MOD_NOREPEAT 标志在 Vista/XP/2K 上不受支持。我怀疑这是你的问题。
您应该检查返回值,它会立即告诉您出现问题。
关于c# - RegisterHotkey 仅适用于 WIndows 7,不适用于 XP、server 2003,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103059/