public bool RemoveHotKey(HotKeyAction hotKey) { if (_processor.UnregisterHotKey(hotKey.Id)) { return(_hotKeys.Remove(hotKey.Id)); } return(false); }
//======================================================================================== // Constructor //======================================================================================== /// <summary> /// Initializes a new instance with the specified properties. /// </summary> /// <param name="action">The action associated with this key sequence.</param> /// <param name="code">The primary keyboard key-code identifier.</param> /// <param name="modifier">The secondary keyboard modifier such as Ctrl or Alt.</param> public HotKey(HotKeyAction action, Keys code, KeyModifier modifier) { counter++; this.Action = action; this.HotId = counter; this.Code = code; this.Modifier = modifier; }
//======================================================================================== // Constructor //======================================================================================== /// <summary> /// Initializes a new instance with the specified properties. /// </summary> /// <param name="action">The action associated with this key sequence.</param> /// <param name="hotID">The internal unique ID to assign to this instance.</param> /// <param name="code">The primary keyboard key-code identifier.</param> /// <param name="modifier">The secondary keyboard modifier such as Ctrl or Alt.</param> public HotKey(HotKeyAction action, Keys code, KeyModifier modifier) { counter++; this.Action = action; this.HotID = counter; this.Code = code; this.Modifier = modifier; }
private void Update() { for (int i = 0; i < hotkeyActions.Count; i++) { HotKeyAction hka = hotkeyActions[i]; if (Input.GetKeyDown(hka.key)) { hka.Toggle(); } } }
public HotKeyAction AddHotKey(ModifierKeys modifiers, Key key, Action action) { int id = _hotKeys.Count; if (_processor.RegisterHotKey(id, modifiers, key)) { var hotKey = new HotKeyAction(id, action); _hotKeys.Add(id, hotKey); return(hotKey); } return(null); }
/// <summary> /// 前置Message过滤器 /// </summary> /// <param name="m">消息句柄</param> /// <returns>是否过滤</returns> public bool PreFilterMessage(ref Message m) { if (m.Msg == WM_HOTKEY) { if (HotKeyAction.IsNotNull() && RegisterdHotKeys.ContainsKey((int)m.WParam)) { HotKeyAction.Invoke((int)m.WParam); return(true); } } return(false); }
void RegisterHotKey(string key, HotKeyAction action) { _actionKey.Remove(action); _keyAction.RemoveByValue(action); if (!string.IsNullOrEmpty(key) && key != "None") { _keyAction.Remove(key); _actionKey.RemoveByValue(key); _keyAction.Add(key, action); _actionKey.Add(action, key); } }
/// <summary> /// Выполняет указанное действие горячей клавиши /// </summary> public static void Run(HotKeyAction action, ISberBankApplication sberBank, object param) { if (locks[action]) { //Trace.WriteLine(String.Format("DiagnosticAction {0} is LOCKED", action)); return; } if (ThreadRequired(action)) { ThreadPool.QueueUserWorkItem(p => { RunCore(action, sberBank, param); }); } else { RunCore(action, sberBank, param); } }
/// <summary> /// Выполняет указанное действие горячей клавиши /// </summary> private static void RunCore(HotKeyAction action, ISberBankApplication sberBank, object param) { locks[action] = true; try { Console.Beep(); switch (action) { case HotKeyAction.OpenLogFolder: OpenLogFolder(sberBank); break; case HotKeyAction.LogRuntimeInfo: WriteRuntimeInfoToLog(sberBank); break; case HotKeyAction.LogComment: WriteLogComment(sberBank, param); break; case HotKeyAction.DeleteLogFiles: DeleteLogFiles(sberBank); break; case HotKeyAction.NetworkControl: NetworkControl(sberBank); break; case HotKeyAction.OpenLogFile: OpenLogFile(sberBank); break; case HotKeyAction.LogControl: LogControl(sberBank); break; } } catch (Exception e) { MessageBox.Show(String.Format("Ошибка при выполнении действия {0}\r\n\r\n{1}", action, e.Message), ApplicationServices.GetApplicationName()); } finally { locks[action] = false; } }
/// <summary> /// Ensure a HotKey exists in the given map for the specified action. /// </summary> /// <param name="map">The key map to scan.</param> /// <param name="action">The action to define.</param> /// <param name="keys">The primary key to define.</param> /// <param name="modifier">The secondary key modifiers to define.</param> private void MergeMap( HotKeyCollection map, HotKeyAction action, Keys keys, KeyModifier modifier) { if (!map.Contains(action)) { if (map.Contains(keys, modifier)) { // can't have two actions with same key sequence so we need to randomize // this sequence. This would only occur when a new version of iTuner // introduces a new action whose default sequence matches the user-defined // sequence of an existing action. keys = Keys.None; modifier = KeyModifier.None; } // Add will add the HotKey in the order prescribed by the HotKeyAction enum map.Add(new HotKey(action, keys, modifier)); } }
public void RegisterHotKey(Keys key, ModifierKeys modifiers, Action <Keys, ModifierKeys> action) { uint param = GetKeyParam(key, modifiers); if (m_keyActions.ContainsKey(param)) { throw new InvalidOperationException(Invariant($"Hotkey ({key}, {modifiers}) is already registered.")); } int id = sm_nextID++; if (!NativeMethods.RegisterHotKey(m_hWnd, id, (uint)modifiers | NoRepeat, (uint)key)) { throw new InvalidOperationException(Invariant($"Couldn't register hotkey ({key}, {modifiers}): error {Marshal.GetLastWin32Error()}")); } m_keyActions[param] = new HotKeyAction { ID = id, Key = key, ModifierKeys = modifiers, Action = action }; }
private void OnChordPressed(int chordId) { //get action HotKeyAction action = actions[chordId]; stateTimer.UpdateStateText(String.Format("Выполняется {0}...", action), true); //get param object param = null; if (action == HotKeyAction.LogComment) { inputForm.Style = InputFormStyle.ShowButtons | InputFormStyle.Multiline; inputForm.Setup(Common.LogCommentCaption); if (inputForm.ShowDialog(this) != DialogResult.OK) { return; } param = inputForm.GetResult(); } else if (action == HotKeyAction.DeleteLogFiles) { if (MessageBox.Show(this, Common.LogDeleteFilesQuestion, ApplicationServices.GetApplicationName(), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } else if (action == HotKeyAction.ShowExtensionFilter) { if (CheckTechnicalPassword()) { ShowExtensionFilter(); } return; } //run HotKeyHelper.Run(action, sberBank, param); }
//======================================================================================== // Methods //======================================================================================== /// <summary> /// Register a new hot key sequence, associating it with the specified action. /// </summary> /// <param name="code">The primary keyboard key-code identifier.</param> /// <param name="modifier">The secondary keyboard modifiers bit mask.</param> /// <param name="action">The well-known action to associated with the hot key.</param> public void RegisterHotKey(Keys code, KeyModifier modifier, HotKeyAction action) { HotKey key = new HotKey(action, code, modifier); bool ok = true; if (code != Keys.None) { try { ok = KeyInterops.RegisterHotKey(window.Handle, key.HotId, (int)modifier, (int)code); } catch (Exception exc) { Logger.WriteLine("RegisterHotKey", exc); } } if (ok) { keys.Add(key.Action, key); } else { MessageWindow.Show(string.Format(Resx.HotKeyNotRegistered, key.Action, key)); key.Code = Keys.None; key.Modifier = KeyModifier.None; if (keys.ContainsKey(action)) { keys[action] = key; } else { keys.Add(action, key); } } }
/// <summary> /// Convert from a HotKeyAction enumeration value to a descriptive string. /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert( object value, Type targetType, object parameter, CultureInfo culture) { HotKeyAction action = (HotKeyAction)value; switch (action) { case HotKeyAction.PlayPause: return(Resx.ActionPlayPause); case HotKeyAction.NextTrack: return(Resx.ActionNextTrack); case HotKeyAction.PrevTrack: return(Resx.ActionPrevTrack); case HotKeyAction.VolumeUp: return(Resx.ActionVolumeUp); case HotKeyAction.VolumeDown: return(Resx.ActionVolumeDown); case HotKeyAction.Mute: return(Resx.ActionMute); case HotKeyAction.ShowiTunes: return(Resx.ActionShowiTunes); case HotKeyAction.ShowiTuner: return(Resx.ActionShowiTuner); case HotKeyAction.ShowLyrics: return(Resx.ActionShowLyrics); } return(String.Empty); }
public HotKeySetting(HotKeyAction action, bool global, string keyCode) { Action = action; Global = global; KeyCode = keyCode; }
//======================================================================================== // Methods //======================================================================================== /// <summary> /// Register a new hot key sequence, associating it with the specified action. /// </summary> /// <param name="code">The primary keyboard key-code identifier.</param> /// <param name="modifier">The secondary keyboard modifiers bit mask.</param> /// <param name="action">The well-known action to associated with the hot key.</param> public void RegisterHotKey(Keys code, KeyModifier modifier, HotKeyAction action) { HotKey key = new HotKey(action, code, modifier); bool ok = true; if (code != Keys.None) { try { ok = KeyInterops.RegisterHotKey(window.Handle, key.HotID, (int)modifier, (int)code); } catch (Exception exc) { Logger.WriteLine("RegisterHotKey", exc); } } if (ok) { keys.Add(key.Action, key); } else { MessageWindow.Show( String.Format(Resx.HotKeyNotRegistered, key.Action, key.ToString())); key.Code = Keys.None; key.Modifier = KeyModifier.None; if (keys.ContainsKey(action)) { keys[action] = key; } else { keys.Add(action, key); } } }
public void AddHotKey(HotKeyAction hotKeyAction) { hotkeyActions.Add(hotKeyAction); }
/// <summary> /// Требуется ли выполнение в отдельном потоке /// </summary> private static bool ThreadRequired(HotKeyAction action) { return(action != HotKeyAction.LogComment); }
/// <summary> /// Determines if the specified hot key action is defined in the collection. /// </summary> /// <param name="action">The HotKeyAction to match</param> /// <returns><b>true</b> if the collections contains a HotKey for this action.</returns> public bool Contains(HotKeyAction action) { return(this.Any(p => p.Action == action)); }