/// <summary> /// 注册热键 /// </summary> public int RegisterHotkey(Keys key, KeyFlags keyflags, HotkeyEventHandler handler) { var hotkeyid = GlobalAddAtom(Guid.NewGuid().ToString()); RegisterHotKey(hWnd, hotkeyid, (uint)keyflags, (uint)key); dictionary.Add(hotkeyid, handler); return((int)hotkeyid); }
/* public enum Modifiers { None = 0x00, LCtrl = 0x01, LShift = 0x02, LAlt = 0x04, LWindows = 0x08, RCtrl = 0x10, RShift = 0x20, RAlt = 0x40, RWindows = 0x80 } */ /// <summary> /// Set a hotkey. (Catch the hotkey in WndProc(Message msg) by checking msg.Msg == WM_HOTKEY) /// </summary> /// <param name="KeyMods">Modifier keys (Ctrl, Alt, Shift, Windows key)</param> /// <param name="KeyCode">Keycode</param> /// <returns></returns> public bool HotkeySet(KeyModifiers KeyMods, Keys KeyCode, HotkeyEventHandler eventHandler) { //Remove the key first: HotkeyUnset(KeyMods, KeyCode); //Add the new key pair to our hotkeypairs array: Array.Resize(ref HotkeyPairs, HotkeyPairs.Length+1); myID++; //increment the ID value (this only has to be a unique value per hotkey pair) so we can use an index to remove keypairs. HotkeyPairs[HotkeyPairs.Length - 1].ID = myID; HotkeyPairs[HotkeyPairs.Length - 1].KeyMods = KeyMods; HotkeyPairs[HotkeyPairs.Length - 1].KeyCode = KeyCode; HotkeyPairs[HotkeyPairs.Length - 1].eventHotkey = eventHandler; //Register the new key: return (RegisterHotKey(myhWnd, myID++, KeyMods, KeyCode)); }