public InputKeyEventArgs(KeyDown newKey) { InputKey = newKey; }
private void OnInputKey(KeyDown inputKey) { char?chr; if (inputKey.Key == Key.Return || inputKey.Key == Key.Enter) { _currentHash = Guid.Empty; _currentInput = _currentInput + Environment.NewLine; OnCommand(_currentInput); _inputHistory.AddPrevious(_currentInput); _currentInput = string.Empty; _position = 0; OnInputChanged(_currentInput, _position); } else if (inputKey.Key == Key.Back) { if (_currentInput.Length == 0 || _position <= -_currentInput.Length) { return; } _currentInput = _currentInput.Remove(_currentInput.Length + _position - 1, 1); } else if (inputKey.Key == Key.Home) { _position = -_currentInput.Length; } else if (inputKey.Key == Key.End) { _position = 0; } else if (inputKey.Key == Key.Delete) { if (_position < 0) { _currentInput = _currentInput.Remove(_currentInput.Length + _position, 1); _position++; } } else if (inputKey.Key == Key.Left) { if (_position > (1 - (_currentInput.Length + 1))) { _position--; } } else if (inputKey.Key == Key.Right) { if (_position < 0) { _position++; } } else if (inputKey.Key == Key.Up) { var prev = _inputHistory.GetPrevious(_currentHash); if (prev != null) { _currentHash = prev.Value.Key; _currentInput = prev.Value.Value; _position = _currentInput.Length; } } else if (inputKey.Key == Key.Down) { var next = _inputHistory.GetNext(_currentHash); if (next != null) { _currentHash = next.Value.Key; _currentInput = next.Value.Value; _position = 0; } else { _currentHash = Guid.Empty; _currentInput = ""; _position = 0; } } else if (inputKey.Character != '\0') { // try get Character if (_position == 0) { _currentInput += inputKey.Character; } else { _currentInput = _currentInput.Insert(_currentInput.Length + _position, inputKey.Character.ToString()); //_position++; } } else { return; } OnInputChanged(_currentInput, _position); }