public Hotkey(uint modifiers, Keys hotkey) { id = new Random().Next(); this.modifiers = modifiers; this.hotkey = hotkey; Application.AddMessageFilter(this); }
/// <summary> /// 注册系统热键 /// </summary> /// <param name="窗口句柄">本程序的窗口句柄,用于接收热键,通过窗体重写WndProc(ref Message m)方法实现接收热键事件,判断当m.Msg为0x0312时触发热键行为,热键编号通过m.WParam获得</param> /// <param name="编号">热键独立编号</param> /// <param name="辅助键">None = 0, Alt = 1, crtl= 2, Shift = 4, Windows = 8,多个辅助键用与运算组合</param> /// <param name="按键">按键</param> public static void 注册系统热键(IntPtr 窗口句柄, int 编号, uint 辅助键, Keys 按键) { RegisterHotKey(窗口句柄, 编号, 辅助键, 按键); }
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);