コード例 #1
0
 private HotkeyController()
 {
     sc = SessionController.getInstance();
     intitialiseModifierDictionary();
     initialiseHotkeyDictionary();
     currentHotkeyModifier = getModifier();
 }
コード例 #2
0
        public HotkeyModifier getModifier()
        {
            HotkeyModifier m = null;

            modifierDictionary.TryGetValue((Modifier)Properties.Settings.Default.HotkeyModifier, out m);
            return(m);
        }
コード例 #3
0
        public void Modify(KeyCode keyCode, HotkeyModifier modifier)
        {
            appliedKey      = keyCode;
            appliedModifier = modifier;

            EventHandler.ExecuteEvent(this, GameEvents.HotkeyBindingChanged);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
        private void OnHotkeyPressed(HotkeyModifier arg1, Key arg2)
        {
            IHotkeyProcessor processor = AssociatedObject.DataContext as IHotkeyProcessor;

            if (processor != null)
            {
                processor.ProcessShortcut(new Shortcut((KeyEnum)arg2, arg1));
            }
        }
コード例 #7
0
 private void removeProtectedHotkeys(HotkeyModifier modifier)
 {
     if (modifier != null)
     {
         foreach (char c in modifier.ProtectedKeys)
         {
             // Remove any protected keys
             hotkeyDictionary.Remove(c);
         }
     }
 }
コード例 #8
0
            // 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);
            }
コード例 #9
0
        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);
        }
コード例 #10
0
            // 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);
            }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
ファイル: HotkeyChooser.cs プロジェクト: trogper/kittysm
        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();
        }
コード例 #13
0
        /// <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());
        }
コード例 #14
0
        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));
            }
        }
コード例 #15
0
ファイル: Shortcut.cs プロジェクト: FlaviusHouk/Dali
 public Shortcut(KeyEnum key, HotkeyModifier modifier)
 {
     Key      = key;
     Modifier = modifier;
 }
コード例 #16
0
 public HotkeyModifier[] getAllModifiers()
 {
     HotkeyModifier[] array = new HotkeyModifier[modifierDictionary.Count];
     modifierDictionary.Values.CopyTo(array, 0);
     return(array);
 }
コード例 #17
0
ファイル: Keyboard.cs プロジェクト: mfrischknecht/sextant
 public static extern bool RegisterHotKey(IntPtr window, int id, HotkeyModifier modifiers, HotkeyKey key);
コード例 #18
0
 private void Awake()
 {
     modifierKeyCode = modifier.ToKeyCode();
     appliedKey      = key;
     appliedModifier = modifier;
 }