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()); }
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; }
public override bool Equals(object obj) { if (!(obj is KeysWithExtended)) { return(false); } KeysWithExtended keysWithExtended = obj as KeysWithExtended; return(this.keycode == keysWithExtended.keycode); }
private bool ModifiersContains(KeysWithExtended key) { foreach (KeysWithExtended k in _modifiers) { if (k == key) { return(true); } } return(false); }
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(); }
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); }
private void ModifiersRemove(KeysWithExtended key) { for (int i = 0; i < _modifiers.Count; i++) { KeysWithExtended k = _modifiers[i]; if (k == key) { _modifiers.RemoveAt(i); i--; } } }
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; } }
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()); }
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); }
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); }
public KeyToHookInformation(KeysWithExtended key, bool keyDown) { this.Key = new KeysWithExtended(key); this.KeyDown = keyDown; this.SeenAt = DateTime.Now; }
public KeysWithExtended(KeysWithExtended keysWithExtended) { this.keycode = keysWithExtended.keycode; }