I got stuck.
Right now, I am using the following code to listen to hotkeys:
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd,
int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312)
{
// whatever i need
}
base.WndProc(ref m);
}
and this function to register hotkey:
Form1.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 0, (int)chr);
it works perfectly.
my question is how do I register multiple hotkeys as the same combination, for example:
- A+B+C+D
- ALT+SHIFT+B
- CTRL+ALT+SHIFT+X
edit: I found out (like Zooba said) how to "decrypt" which hotkey was sent and here's the solution:
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF);
if ((modifier + "+" + key == "Alt+S"))
{
//do what ever I need.
}
}
base.WndProc(ref m);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…