我对此进行了编码,并且它更早地工作了!alt+1 和 alt+2 的全局热键。当我关闭我的项目时,我不小心按下了一个键或其他东西,现在由于某种原因只有 alt+1 正在工作,并且没有其他 alt+ 数字的组合......
[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);
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(System.Int32 vKey);
const int MYACTION_HOTKEY_ID = 1;
public Form1()
{
InitializeComponent();
RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 1, (int)Keys.D1);
RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 1, (int)Keys.D2);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312 && m.WParam.ToInt32() == MYACTION_HOTKEY_ID && (GetAsyncKeyState(Keys.D1) == -32767))
{
Console.Write("alt+1");
}
if (m.Msg == 0x0312 && m.WParam.ToInt32() == MYACTION_HOTKEY_ID && (GetAsyncKeyState(Keys.D2) == -32767))
{
Console.Write("alt+2");
}
base.WndProc(ref m);
}
有人有想法么?