我正在使用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);
}在我的Windows7PC上,这是可行的,但在XP或windows Server2003上就不行了。你知道哪里出问题了吗?
发布于 2011-05-24 05:13:42
查看RegisterHotKey的文档,它指出Vista/XP/2K不支持MOD_NOREPEAT标志。我怀疑这就是你的问题。
你应该检查返回值,它会立即告诉你出了什么问题。
https://stackoverflow.com/questions/6103059
复制相似问题