日期:2014-05-17 浏览次数:20977 次
protected override void WndProc(ref Message m) { const int WM_HOTKEY = 0x0312; if (m.Msg == WM_HOTKEY) { int id = m.WParam.ToInt32(); if (id == "注册热键的ID") { //响应程序 } } base.WndProc(ref m); } /// <summary> /// 注册热键 /// </summary> /// <param name="fsModifiers"></param> /// <param name="vk"></param> /// <returns></returns> public bool RegisterHotKey(int KeyId, uint fsModifiers, uint vk) { UnregisterHotKey(KeyId); return Base.RegisterHotKey(this.Handle, KeyId, fsModifiers, vk); } /// <summary> /// 注销热键 /// </summary> /// <returns></returns> public bool UnregisterHotKey(int KeyId) { return Base.UnregisterHotKey(this.Handle, KeyId); } //注册热键 RegisterHotKey(text.keyId, (uint)text.wParam, (uint)text.lParam) //调用DLL [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnregisterHotKey(IntPtr hWnd, int id);