bool Contains(KeyChord keyChord) { if (((numButtons <= keyChord.numButtons) && (numKeys <= keyChord.numKeys)) || (numButtons < keyChord.numButtons) || (numKeys < keyChord.numKeys)) { return(false); } if (keyChord._buttons != null) { for (int i = 0; i < keyChord._buttons.Count; ++i) { if (!HasButton(keyChord._buttons[i])) { return(false); } } } if (keyChord._keys != null) { for (int i = 0; i < keyChord._keys.Count; ++i) { if (!HasKey(keyChord._keys[i])) { return(false); } } } return(true); }
public void RestoreFromJSON(JSONNode mapJSON) { try { commandName = mapJSON["action"].Value; slot = mapJSON["slot"].AsInt; isAxis = mapJSON["isAxis"].Value != "false"; if (isAxis) { chord = KeyChord.FromJSON(mapJSON["chord"]); axisName = mapJSON["axis"].Value; reversed = mapJSON["reversed"].Value == "true"; isMouse = axisName?.StartsWith("Mouse") ?? false; } else { leftChord = KeyChord.FromJSON(mapJSON["leftChord"]); rightChord = KeyChord.FromJSON(mapJSON["rightChord"]); } } catch (System.Exception e) { SuperController.LogError($"Keybindings: invalid keybinding for '{commandName}' slot {slot}: {e}"); } }
public void Added(KeyChord keyChord) { if (!IsChild(keyChord)) { if (Contains(keyChord)) { if (keyChord._parent != null) { keyChord._parent._children.Remove(keyChord); } keyChord._parent = this; _children.Add(keyChord); } else if (keyChord.Contains(this) && !keyChord.IsChild(this)) { if (_parent != null) { _parent._children.Remove(this); } _parent = keyChord; keyChord._children.Add(this); } } }
KeyChord InternalRegisterKeyChord(IList <InputKey> keys, IList <int> buttons) { if (((keys == null) || (keys.Count < 1)) && ((buttons == null) || (buttons.Count < 1))) { return(null); } var chord = FindKeyChord(keys, buttons); if (chord != null) { ++chord.refCount; return(chord); } chord = new KeyChord(keys, buttons); for (int i = 0; i < _keyChords.Count; ++i) { _keyChords[i].Added(chord); } _keyChords.Add(chord); return(chord); }
public AnalogMap(KeyChord leftChord, KeyChord rightChord, string commandName, int slot = 0) { isAxis = false; chord = KeyChord.empty; axisName = null; reversed = false; this.leftChord = leftChord; this.rightChord = rightChord; this.commandName = commandName; this.slot = slot; }
bool IsChild(KeyChord keyChord) { for (var p = keyChord._parent; p != null; p = p._parent) { if (ReferenceEquals(p, this)) { return(true); } } return(false); }
public AnalogMap(KeyChord chord, string axisName, bool reversed, string commandName, int slot = 0) { isAxis = true; leftChord = KeyChord.empty; rightChord = KeyChord.empty; this.chord = chord; this.axisName = axisName; this.commandName = commandName; this.reversed = reversed; this.slot = slot; isMouse = axisName?.StartsWith("Mouse") ?? false; }
void InternalUnregisterKeyChord(KeyChord keyChord) { if (--keyChord.refCount == 0) { if (_keyChords.Remove(keyChord)) { for (int i = 0; i < _keyChords.Count; ++i) { _keyChords[i].Removed(keyChord); } } } }
private IEnumerator RecordKeys(UIDynamicButton btn, ICommandInvoker commandInvoker, Color btnColor, int slot) { isRecording = true; var expire = float.MaxValue; var setKeybindingList = new List <KeyChord>(); while (Time.unscaledTime < expire) { yield return(0); if (Input.GetKeyDown(KeyCode.Mouse0)) { continue; } if (Input.GetKeyUp(KeyCode.Mouse0)) { // Apply SaveKeyMap(setKeybindingList, commandInvoker, slot); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } if (Input.GetKeyDown(KeyCode.Escape)) { // Cancel StopRecording(btn, btnColor, commandInvoker, slot); yield break; } var key = KeyCodes.bindableKeyCodes.GetCurrentDown(); if (key == KeyCode.None) { continue; } if (!KeyChord.IsValid(key)) { continue; } var ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); var altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); var shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); var binding = new KeyChord(key, ctrlDown, altDown, shiftDown); setKeybindingList.Add(binding); btn.label = setKeybindingList.GetKeyChordsAsString(); expire = Time.unscaledTime + Settings.TimeoutLen; } SaveKeyMap(setKeybindingList, commandInvoker, slot); StopRecording(btn, btnColor, commandInvoker, slot); }
public bool TryGet(KeyChord source, out KeyMapTreeNode result) { for (var i = 0; i < next.Count; i++) { if (!next[i].keyChord.Equals(source)) { continue; } result = next[i]; return(true); } result = null; return(false); }
public void Process(InputMessageConverter inputMessage) { var input = inputMessage.GetInputDescriptor <KeyboardMessage>(); var virtualKey = KeyChord.GetVirtualKey(input.Key); if (virtualKey != 0) { Keyboard.SetKey(virtualKey, (ModifierKeys)input.Modifiers, input.IsPressed); } else if (input.Key.Length > 1) { throw new ArgumentException($"Invalid input key '{input.Key}'."); } else { Keyboard.SetKey(input.Key[0], (ModifierKeys)input.Modifiers, input.IsPressed); } _logger.LogInformation($"Key: {input.Key} {input.IsPressed}"); }
public bool Removed(KeyChord keyChord) { if (ReferenceEquals(keyChord, _parent)) { _parent = null; } else { if (_children.Remove(keyChord)) { for (int i = 0; i < keyChord._children.Count; ++i) { _children.Add(keyChord._children[i]); } return(true); } } return(false); }
private void SaveAnalogMap(ICommandInvoker commandInvoker, KeyChord binding, AnalogMap map) { var previousMap = analogMapManager.maps.FirstOrDefault(m => m.commandName == commandInvoker.commandName); if (previousMap != null) { remoteCommandsManager.UpdateValue(previousMap.commandName, 0); analogMapManager.maps.Remove(previousMap); } var conflictMap = analogMapManager.maps.FirstOrDefault(m => m.chord.Equals(binding) && m.axisName == map.axisName && m.leftChord.Equals(map.leftChord) && m.rightChord.Equals(map.rightChord)); if (conflictMap != null) { remoteCommandsManager.UpdateValue(conflictMap.commandName, 0); analogMapManager.maps.Remove(conflictMap); var conflictRow = _rowGroups.SelectMany(g => g).FirstOrDefault(r => r.commandName == conflictMap.commandName); if (conflictRow != null) { if (conflictMap.slot == 0) { conflictRow.bindingBtn1.label = _notBoundButtonLabel; } else if (conflictMap.slot == 0) { conflictRow.bindingBtn2.label = _notBoundButtonLabel; } else { throw new InvalidOperationException("Unknown slot " + conflictMap.slot); } } SuperController.LogMessage($"Keybindings: Reassigned binding from {conflictMap.commandName} to {commandInvoker.commandName}"); } analogMapManager.maps.Add(map); }
private IEnumerator RecordAnalog(UIDynamicButton btn, ICommandInvoker commandInvoker, Color btnColor, int slot) { isRecording = true; var leftKeybinding = KeyChord.empty; while (true) { yield return(0); if (Input.GetKeyDown(KeyCode.Mouse0)) { continue; } if (Input.GetKeyUp(KeyCode.Mouse0)) { var mapped = analogMapManager.GetMapByName(commandInvoker.commandName, slot); if (mapped != null) { analogMapManager.maps.Remove(mapped); } break; } if (Input.GetKeyDown(KeyCode.Escape)) { break; } var ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); var altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); var shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); var keyUp = KeyCodes.bindableKeyCodes.GetCurrentUp(); if (keyUp != KeyCode.None) { if (!KeyChord.IsValid(keyUp)) { continue; } var binding = new KeyChord(keyUp, ctrlDown, altDown, shiftDown); if (leftKeybinding.key == KeyCode.None) { btn.label = "Type other direction..."; leftKeybinding = binding; continue; } else if (keyUp == leftKeybinding.key) { continue; } var map = new AnalogMap(leftKeybinding, binding, commandInvoker.commandName, slot); SaveAnalogMap(commandInvoker, binding, map); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } foreach (var axisName in _knownAxisNames) { var axisValue = AnalogMap.GetAxis(axisName); if (Mathf.Abs(axisValue) < 0.75f) { continue; } var key = KeyCodes.bindableKeyCodes.GetCurrent(); // We don't want to take over the mouse! if (axisName.StartsWith("Mouse") && key == KeyCode.None && !ctrlDown && !shiftDown && !altDown) { continue; } var binding = new KeyChord(key, ctrlDown, altDown, shiftDown); var map = new AnalogMap(binding, axisName, axisValue < 0, commandInvoker.commandName, slot); SaveAnalogMap(commandInvoker, binding, map); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } } StopRecording(btn, btnColor, commandInvoker, slot); }
public bool Equals(KeyChord other) { return(ctrl == other.ctrl && shift == other.shift && alt == other.alt && key == other.key); }