我找到了这段小代码来注册一个热键:
[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 == 0x0312)
MessageBox.Show("Hotkey pressed");
base.WndProc(ref m);
}
public FormMain()
{
InitializeComponent();
//Alt + A
RegisterHotKey(this.Handle, this.GetType().GetHashCode(), 1, (int)'A');
}
它工作得很好,但我的问题是我想使用两个不同的快捷方式。我知道第二个参数是 id,所以我想我可以创建一个不同的 id 并在 WndProc 函数中添加一个新的 if 语句,但我不确定我将如何去做。
简而言之,我将如何创建第二个快捷方式?
谢谢,