私は立ち往生しました。
現在、次のコードを使用してホットキーをリッスンしています。
[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);
}
そして、ホットキーを登録するこの関数:
Form1.RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 0, (int)chr);
それは完全に機能します。私の質問は、複数のホットキーを同じ組み合わせとして登録する方法です。たとえば、次のようになります。
- A+B+C+D
- Alt+Shift+B
- CTRL+ALT+SHIFT+X
編集:私は(ズーバが言ったように)送信されたホットキーを「復号化」する方法を見つけました。ここに解決策があります:
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);
}