コード例 #1
0
        private void ProcessKeyEvent(Key key, bool value)
        {
            if (currentShortcut != Key.Unknown)
            {
                // If currentShortcut == key, we will restore state by the next call.
                SetKeyStateInternal(currentShortcut, false);
                currentShortcut = Key.Unknown;
            }
            SetKeyStateInternal(key, value);
            if (value && key > Key.LastNormal)
            {
                // Shortcut was simulated by menu item.
                currentShortcut = key;
                return;
            }
            // Give priority to the last pressed key, choose arbitrarily among others.
            Key mainKey = value && Shortcut.ValidateMainKey(key) ? key : FindMainKey();

            if (mainKey == Key.Unknown)
            {
                return;
            }
            if (Key.ShortcutMap.TryGetValue(new Shortcut(GetModifiers(), mainKey), out currentShortcut))
            {
                SetKeyStateInternal(currentShortcut, true);
            }
        }
コード例 #2
0
 private Key FindMainKey()
 {
     for (var i = Key.Unknown; i < Key.LastNormal; i++)
     {
         if (keys[i].CurrentState && Shortcut.ValidateMainKey(i))
         {
             return(i);
         }
     }
     return(Key.Unknown);
 }
コード例 #3
0
        public static Key MapShortcut(Shortcut shortcut)
        {
            if (!Shortcut.ValidateMainKey(shortcut.Main))
            {
                throw new ArgumentException();
            }
            Key key;

            if (!ShortcutMap.TryGetValue(shortcut, out key))
            {
                key = New();
                ShortcutMap.Add(shortcut, key);
            }
            return(key);
        }
コード例 #4
0
        public void AddAlias(Shortcut shortcut)
        {
            if (!Shortcut.ValidateMainKey(shortcut.Main))
            {
                throw new ArgumentException();
            }
            Key key;

            if (!ShortcutMap.TryGetValue(shortcut, out key))
            {
                ShortcutMap.Add(shortcut, this);
            }
            else if (key != this)
            {
                throw new InvalidOperationException();
            }
        }
コード例 #5
0
        private void ProcessKeyEvent(Key key, bool value)
        {
            // Dont let system key repeat events get to us, for our key repeat mechanism to work properly
            if (keys[key].CurrentState && value)
            {
                return;
            }
            var previousCurrentShortcut = currentShortcut;

            if (currentShortcut != Key.Unknown)
            {
                // If currentShortcut == key, we will restore state by the next call.
                SetKeyStateInternal(currentShortcut, false);
                currentShortcut = Key.Unknown;
            }
            SetKeyStateInternal(key, value);
            if (value && key > Key.LastNormal)
            {
                // Shortcut was simulated by menu item.
                currentShortcut = key;
                return;
            }
            // Give priority to the last pressed key, choose arbitrarily among others.
            Key mainKey = value && Shortcut.ValidateMainKey(key) ? key : FindMainKey();

            if (mainKey == Key.Unknown)
            {
                return;
            }
            if (Key.ShortcutMap.TryGetValue(new Shortcut(GetModifiers(), mainKey), out currentShortcut))
            {
                SetKeyStateInternal(currentShortcut, true);
                if (previousCurrentShortcut == currentShortcut)
                {
                    // Prevent setting Repeated = true before key repeat timeout for given key in case
                    // we're here because another key has been released. e.g. releasing key "3" while still holding "Enter" key in edit box (see CIT-783)
                    keys[currentShortcut].Repeated = false;
                }
            }
        }