C# 如何使用user32.dll区分已注册热键
我注册了两个热键C# 如何使用user32.dll区分已注册热键,c#,winforms,user32,global-hotkey,C#,Winforms,User32,Global Hotkey,我注册了两个热键 RegisterHotKey(thiswindow, (uint) WindowKeys.Alt, 1, (int)Keys.D1); RegisterHotKey(thiswindow, (uint) WindowKeys.Alt, 2, (int)Keys.D2); 现在,我如何使用以下方法区分它们: protected override void WndProc(ref Message keyPressed) { if (key
RegisterHotKey(thiswindow, (uint) WindowKeys.Alt, 1, (int)Keys.D1);
RegisterHotKey(thiswindow, (uint) WindowKeys.Alt, 2, (int)Keys.D2);
现在,我如何使用以下方法区分它们:
protected override void WndProc(ref Message keyPressed)
{
if (keyPressed.Msg == 0x0312)
{
if (alt+d1 is pressed)
//do something
if (alt+d2 is pressed)
//do something
}
base.WndProc(ref keyPressed);
}
我在导入user32.dll的WinForm项目中执行此操作。热键ID在WParam中传递,因此
int hotKeyID=keyPressed.WParam.ToInt32()代码>。按下的键和修改器打包在LParam中:var Key=(Keys)(keyPressed.LParam.ToInt32()>>16)代码>和var修饰符=(KeyModifier)(keyPressed.LParam.ToInt32()&0xFF)代码>@Jimi我测试了你的解决方案,它似乎只在关键代码为“1”时才起作用。寄存器hotKey(thiswindow,(uint)WindowKeys.Alt,2,(int)Keys.D2)不会发生任何变化代码>正在注册你应该仔细检查RegisterHotKey函数的定义。@Jimi是的,首先是ID,然后是修饰符。谢谢你的帮助