/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="modifiers"></param> /// <param name="key"></param> /// <param name="callBack"></param> public Hotkey(string name, int modifiers, Keys key, HotkeyCallBackHanlder callBack) { Name = name; Modifiers = modifiers; Key = key; Registered = false; CallBack = callBack; }
// 注册快捷键 public bool Register(int modifiers, Keys vk, HotkeyCallBackHanlder callBack) { int id = hotkeyId++; if (!Windows.Apis.User32.RegisterHotKey(_hWnd, id, modifiers, vk)) { return(false); } hotkeysMap[id] = callBack; return(true); }
// 注销快捷键 public bool UnRegister(HotkeyCallBackHanlder callBack) { foreach (KeyValuePair <int, HotkeyCallBackHanlder> var in hotkeysMap) { if (var.Value == callBack) { Windows.Apis.User32.UnregisterHotKey(_hWnd, var.Key); hotkeysMap.Remove(var.Key); return(true); } } return(false); }