private HotkeyController() { sc = SessionController.getInstance(); intitialiseModifierDictionary(); initialiseHotkeyDictionary(); currentHotkeyModifier = getModifier(); }
public HotkeyModifier getModifier() { HotkeyModifier m = null; modifierDictionary.TryGetValue((Modifier)Properties.Settings.Default.HotkeyModifier, out m); return(m); }
public void Modify(KeyCode keyCode, HotkeyModifier modifier) { appliedKey = keyCode; appliedModifier = modifier; EventHandler.ExecuteEvent(this, GameEvents.HotkeyBindingChanged); }
/// <summary> /// Get Modifier value from given text /// </summary> /// <param name="mods">modifiers. comma separated</param> /// <returns></returns> private static HotkeyModifier GetMofidifier(string mods) { var fms = from m in mods.Split(',') select $"MOD_{m.ToUpperInvariant()}"; HotkeyModifier result = HotkeyModifier.MOD_NoModifier; foreach (var fm in fms) { if (Enum.TryParse <HotkeyModifier>(fm, out HotkeyModifier tmp) == false) { result = HotkeyModifier.MOD_NoModifier; break; } else { if (result == HotkeyModifier.MOD_NoModifier) { result = tmp; } else { result |= tmp; } } } return(result); }
private void addProtectedHotkeys(HotkeyModifier modifier) { foreach (char c in modifier.ProtectedKeys) { // Add the default system hotkeys so they can't be duplicated hotkeyDictionary.Add(c, HotKeyId.HKID_PROTECTED); } }
private void OnHotkeyPressed(HotkeyModifier arg1, Key arg2) { IHotkeyProcessor processor = AssociatedObject.DataContext as IHotkeyProcessor; if (processor != null) { processor.ProcessShortcut(new Shortcut((KeyEnum)arg2, arg1)); } }
private void removeProtectedHotkeys(HotkeyModifier modifier) { if (modifier != null) { foreach (char c in modifier.ProtectedKeys) { // Remove any protected keys hotkeyDictionary.Remove(c); } } }
// All these key methods could be grouped up a lot nicer later using delegates and refs private bool KeysPressed(Event currentEvent, KeyCode key, HotkeyModifier mod) { // If correct key was pressed for the first time if (currentEvent.keyCode == key) { // If the correct modifier was held down if (IsModifierPressed(currentEvent, mod)) { return(true); } } return(false); }
public void setModifier(HotkeyModifier m) { // Remove any protected hotkeys for the old modifier removeProtectedHotkeys(currentHotkeyModifier); // Set the new modifier Properties.Settings.Default.HotkeyModifier = m.Modifier; // Save the current modifier currentHotkeyModifier = getModifier(); // Add in any protected keys for the new modifier addProtectedHotkeys(currentHotkeyModifier); }
// Return true if the correct modifier key is held down private bool IsModifierPressed(Event currentEvent, HotkeyModifier modifier) { // If SHIFT is needed and is held down, return true if (modifier == HotkeyModifier.SHIFT && currentEvent.shift) { return(true); } // If SHIFT is not needed and SHIFT is not held down, return true else if (modifier == HotkeyModifier.NONE && !currentEvent.shift) { return(true); } return(false); }
/// <summary> /// Check to see if the exisiting set of hotkeys contains any protected /// hotkeys for the new modifier /// </summary> /// <param name="modifier"></param> /// <returns></returns> public bool validateNewModifier(HotkeyModifier modifier) { bool result = true; foreach (char c in modifier.ProtectedKeys) { if (hotkeyDictionary.ContainsKey(c)) { HotKeyId id; hotkeyDictionary.TryGetValue(c, out id); if (id != HotKeyId.HKID_PROTECTED) { result = false; } } } return(result); }
private void modifierComboBox_SelectedIndexChanged(object sender, EventArgs e) { HotkeyModifier modifier = (HotkeyModifier)modifierComboBox.SelectedItem; if (hkc.validateNewModifier(modifier) == false) { MessageBox.Show(this, "Your current hotkeys contain one or more protected keys for \n" + "the " + modifier.Description + " modifier: " + modifier.ProtectedKeysDescription + "\n" + "Please disable or remove these hotkeys first." , "Warning" , MessageBoxButtons.OK , MessageBoxIcon.Warning); modifierComboBox.SelectedIndex = currentModifierIndex; return; } updateModifier(); }
/// <summary> /// Registers new global HotKey combination. /// </summary> /// <exception cref="ObjectDisposedException"> /// Current instance has already disposed. /// </exception> /// <param name="key">Used WinForm key enum</param> /// <returns>True if operation was success.</returns> public bool Register(HotkeyModifier modifier, Keys key) { if (IsDisposed) { throw new ObjectDisposedException(nameof(GlobalHotkeyProvider)); } if (IsRegistered) { return(false); } _holdedModifier = modifier; _holdedKeyWinForm = key; _holdedKeyWPF = KeyInterop.KeyFromVirtualKey((int)key); return(InternalRegister()); }
public static KeyCode ToKeyCode(this HotkeyModifier hotkeyModifier) { switch (hotkeyModifier) { case HotkeyModifier.None: return(KeyCode.None); case HotkeyModifier.LeftControl: return(KeyCode.LeftControl); case HotkeyModifier.LeftAlt: return(KeyCode.LeftAlt); case HotkeyModifier.LeftShift: return(KeyCode.LeftShift); default: throw new ArgumentOutOfRangeException(nameof(hotkeyModifier)); } }
public Shortcut(KeyEnum key, HotkeyModifier modifier) { Key = key; Modifier = modifier; }
public HotkeyModifier[] getAllModifiers() { HotkeyModifier[] array = new HotkeyModifier[modifierDictionary.Count]; modifierDictionary.Values.CopyTo(array, 0); return(array); }
public static extern bool RegisterHotKey(IntPtr window, int id, HotkeyModifier modifiers, HotkeyKey key);
private void Awake() { modifierKeyCode = modifier.ToKeyCode(); appliedKey = key; appliedModifier = modifier; }