Exemplo n.º 1
0
        public override string GetDetails()
        {
            StringBuilder sb = new StringBuilder();

            if (Control)
            {
                sb.Append("Control + ");
            }
            if (Shift)
            {
                sb.Append("Shift + ");
            }
            if (Alt)
            {
                sb.Append("Alt + ");
            }
            if (LWin)
            {
                sb.Append("LWin + ");
            }
            if (RWin)
            {
                sb.Append("RWin + ");
            }
            KeysWithExtended keys = new KeysWithExtended(VirtualKey, Extended);

            sb.Append(keys.ToString());
            if (RepeatCount > 1)
            {
                sb.Append("  x" + RepeatCount.ToString());
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
 public KeyCombination(KeyCombination source)
 {
     this._key     = source._key;
     this._keyDown = source._keyDown;
     this._modifiers.AddRange(source._modifiers);
     this._transitionToUp = source._transitionToUp;
     this._lastChange     = source._lastChange;
 }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if (!(obj is KeysWithExtended))
            {
                return(false);
            }

            KeysWithExtended keysWithExtended = obj as KeysWithExtended;

            return(this.keycode == keysWithExtended.keycode);
        }
Exemplo n.º 4
0
 private bool ModifiersContains(KeysWithExtended key)
 {
     foreach (KeysWithExtended k in _modifiers)
     {
         if (k == key)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        public void Add(KeysWithExtended key, bool keyDown)
        {
            lock (this)
            {
                _keys.Add(new KeyToHookInformation(key, keyDown));
                _keysAdded++;
#if EXTENDED_LOGGING
                Log.MainLog.WriteDebug("     Added: " + key.ToString() + " " + (keyDown ? "down" : "up"));
#endif
            }
            _changed.Set();
        }
Exemplo n.º 6
0
        public static KeysWithExtended Parse(string s)
        {
            KeysWithExtended result = new KeysWithExtended(0);

            if (s.StartsWith("^"))
            {
                s = s.Substring(1);
                result.Extended = true;
            }
            result.Keys = NiceKeyName.GetKey(s);
            return(result);
        }
Exemplo n.º 7
0
 private void ModifiersRemove(KeysWithExtended key)
 {
     for (int i = 0; i < _modifiers.Count; i++)
     {
         KeysWithExtended k = _modifiers[i];
         if (k == key)
         {
             _modifiers.RemoveAt(i);
             i--;
         }
     }
 }
Exemplo n.º 8
0
        public void KeyPress(bool keyDown, Keys key, bool extended)
        {
            double now = Utils.Time.GetTime();
            double timeSinceLastChange = now - _lastChange;

            if (timeSinceLastChange > 1000)
            {
                _key = KeysWithExtended.None;
                _modifiers.Clear();
                _keyDown = false;
            }
            _lastChange = now;

            _transitionToUp = (!keyDown && _keyDown);

            KeysWithExtended keys = new KeysWithExtended(key, extended);

            // If we're transitioning from keydowns to keyups we'll stick the last key in the modifiers list
            // because the keys aren't always released in the opposite order they were pressed.
            if (_transitionToUp)
            {
                if ((ModifiersContains(_key) == false) && (_key != KeysWithExtended.None))
                {
                    _modifiers.Add(_key);
                }
            }

            if (ModifiersContains(keys))
            {
                ModifiersRemove(keys);
            }

            if (keyDown)
            {
                if ((_keyDown) && // If the last keystroke was a keydown then we add it to the modifiers
                    (_key != keys))
                {
                    if ((ModifiersContains(_key) == false) && (_key != KeysWithExtended.None))
                    {
                        _modifiers.Add(_key);
                    }
                }
                _key     = keys;
                _keyDown = true;
            }
            else
            {
                _key     = keys;
                _keyDown = false;
            }
        }
Exemplo n.º 9
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            for (int i = 0; i < _keyCodes.Count; i++)
            {
                KeysWithExtended code = new KeysWithExtended(_keyCodes[i]);
                if (i > 0)
                {
                    result.Append("+");
                }
                result.Append(code.ToString());
            }
            if (Name.Length != 0)
            {
                result.Append(" - " + Name);
            }
            return(result.ToString());
        }
Exemplo n.º 10
0
        public bool Remove(KeysWithExtended key, bool keyDown)
        {
            bool found = false;

            lock (this)
            {
                for (int i = 0; i < _keys.Count; i++)
                {
                    KeyToHookInformation info = _keys[i];

                    if (_testModifiers && (info.Key == key) && (info.KeyDown == keyDown))
                    {
#if EXTENDED_LOGGING
                        Log.MainLog.WriteDebug("     Removed: " + info.Key.ToString() + " " + (info.KeyDown ? "down" : "up"));
#endif
                        found = true;
                        _keys.RemoveAt(i--);
                    }
                    else if (!_testModifiers && (info.Key.Keys == key.Keys) && (info.KeyDown == keyDown))
                    {
#if EXTENDED_LOGGING
                        Log.MainLog.WriteDebug("     Removed: " + info.Key.ToString() + " " + (info.KeyDown ? "down" : "up"));
#endif
                        found = true;
                        _keys.RemoveAt(i--);
                    }
                    else if (DateTime.Now.Subtract(_keys[i].SeenAt).TotalMilliseconds > _timeout)
                    {
#if EXTENDED_LOGGING
                        Log.MainLog.WriteDebug("     Removed (timeout): " + info.Key.ToString() + " " + (info.KeyDown ? "down" : "up"));
#endif
                        _keys.RemoveAt(i--);
                        _keysRemovedDueToTimeout++;
                    }
                }
            }
            if (found)
            {
                _changed.Set();
            }
            return(found);
        }
Exemplo n.º 11
0
        private static bool IsModifierKey(KeysWithExtended keyWithExtended)
        {
            Keys key = keyWithExtended.Keys;

            if (keyWithExtended.IsShiftKey)
            {
                return(true);
            }
            if (keyWithExtended.IsControlKey)
            {
                return(true);
            }
            if (keyWithExtended.IsAltKey)
            {
                return(true);
            }
            if ((key == Keys.LWin) || (key == Keys.RWin))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 12
0
 public KeyToHookInformation(KeysWithExtended key, bool keyDown)
 {
     this.Key     = new KeysWithExtended(key);
     this.KeyDown = keyDown;
     this.SeenAt  = DateTime.Now;
 }
Exemplo n.º 13
0
 public KeysWithExtended(KeysWithExtended keysWithExtended)
 {
     this.keycode = keysWithExtended.keycode;
 }