/// <summary> /// Checks whether the mouse left or entered this control (or one of its childcontrols) /// </summary> /// <param name="cursorPoint"></param> /// <param name="result"></param> protected void CheckMouseEvents(TVector2 cursorPoint, InputUtilities inputUtils, ref MouseEvent result) { inputUtils.Mouse.CurrentMouseArgs.PosOnForm = cursorPoint; foreach (Control <TRenderer, TColor, TVector2, TFont> control in ChildControls) { if (result.Handled) { return; } if (!control.Visible) { continue; } if (!inputUtils.MouseChanged) { continue; } result.Depth++; control.CheckMouseEvents(cursorPoint, inputUtils, ref result); result.Depth--; } if (!result.Handled) { this.MouseOver = this.CheckMouseOver(cursorPoint); if (this.MouseOver) { result.Handled = true; if (!inputUtils.MouseChanged) { return; } if ((inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Left || inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Right || inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Middle || inputUtils.Mouse.CurrentMouseArgs.Wheel) && inputUtils.Mouse.CurrentMouseArgs.UpOrDown == MouseEventExtArgs.UpDown.Down) { OnMouseClickEventDown(inputUtils.Mouse.CurrentMouseArgs); } if ((inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Left || inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Right || inputUtils.Mouse.CurrentMouseArgs.Button == MouseButtons.Middle || inputUtils.Mouse.CurrentMouseArgs.Wheel) && inputUtils.Mouse.CurrentMouseArgs.UpOrDown == MouseEventExtArgs.UpDown.Up) { OnMouseClickEventUp(inputUtils.Mouse.CurrentMouseArgs); } if (inputUtils.Mouse.CurrentMouseArgs.Wheel) { OnMouseWheelEvent(inputUtils.Mouse.CurrentMouseArgs); } if (!LastMousePos.Equals(cursorPoint)) { OnMouseMovedEvent(inputUtils.Mouse.CurrentMouseArgs); LastMousePos = cursorPoint; } } } }
// Update is called once per frame void Update() { if (mouseQuery.ClickedBody != null) { // Attach with mouse joint if (mouseJoint == null) { mouseJoint = gameObject.AddComponent <LPJointMouse>(); mouseJoint.BodyA = mouseQuery.ClickedBody.gameObject; mouseJoint.BodyB = mouseQuery.ClickedBody.gameObject; mouseJoint.MaximumForce = 500; mouseJoint.Initialise(lpMan); } bool aTouch = false; Vector3 touchPos = new Vector3(); InputUtilities.GetMouseInput(out aTouch, out touchPos); if (aTouch) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(touchPos); mouseJoint.SetTarget(mousePos); } } else { TryDeleteMouseJoint(); } }
private static bool TryGetValue( IReadOnlyDictionary <char, ConsoleInputOperation> charBindings, IReadOnlyDictionary <ConsoleKey, ConsoleInputOperation> keyBindings, IReadOnlyDictionary <ConsoleKey, ConsoleInputOperation> shiftKeyBindings, ConsoleKey key, ConsoleModifiers modifiers, out ConsoleInputOperation op) { var shiftModifiers = modifiers & ConsoleModifiers.Shift; var charWithoutNonShiftModifiers = InputUtilities.TryGetSingleChar(key, shiftModifiers); // It's important that we try the character bindings first. if (charWithoutNonShiftModifiers.HasValue && charBindings.TryGetValue(char.ToLowerInvariant(charWithoutNonShiftModifiers.Value), out op)) { return(true); } if (modifiers.HasFlag(ConsoleModifiers.Shift) && (shiftKeyBindings != null) && shiftKeyBindings.TryGetValue(key, out op)) { return(true); } return(keyBindings.TryGetValue(key, out op)); }
private bool DoTwoCodePathsAgree(ConsoleKey key, ConsoleModifiers modifiers) { var portableChars = InputUtilities.GetCharsPortable(key, modifiers); var winChars = NClap.Utilities.Windows.InputUtilities.GetChars(key, modifiers); if (portableChars.Length != winChars.Length) { Console.Error.WriteLine( $"Different char counts for '{key}' (mods={modifiers}): " + $"portable=[{string.Join(", ", portableChars.Select(c => ((byte)c).ToString()))}] " + $"win=[{string.Join(", ", winChars.Select(c => ((byte)c).ToString()))}]"); return(false); } for (var i = 0; i < portableChars.Length; ++i) { if (portableChars[i] != winChars[i]) { Console.Error.WriteLine( $"Different chars for '{key}' (mods={modifiers}): " + $"portable=[{string.Join(", ", portableChars.Select(c => ((byte)c).ToString()))}] " + $"win=[{string.Join(", ", winChars.Select(c => ((byte)c).ToString()))}]"); return(false); } } return(true); }
static void Main(string[] args) { Console.WriteLine("Change overlay attached window by pressing F5"); Console.WriteLine("It will attach to currently active window"); Console.WriteLine("Trackbar can be controled with mouse wheel"); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); input = new InputUtilities(); var hWnd = WinAPI.GetForegroundWindow(); using (SHDXOverlay = new SharpDXOverlay()) { SHDXOverlay.Attach(hWnd); SHDXOverlay.TickEvent += overlay_TickEvent; InitializeComponents(); SharpDXRenderer renderer = SHDXOverlay.Renderer; TextFormat smallFont = renderer.CreateFont("smallFont", "Century Gothic", 10f); TextFormat largeFont = renderer.CreateFont("largeFont", "Century Gothic", 14f); TextFormat heavyFont = renderer.CreateFont("heavyFont", "Century Gothic", 14f, SharpDX.DirectWrite.FontStyle.Normal, FontWeight.Heavy); windowMenu.Font = smallFont; windowMenu.Caption.Font = largeFont; SHDXOverlay.ChildControls.Add(windowMenu); System.Windows.Forms.Application.Run(SHDXOverlay); } }
/// <summary> /// Performs an update on this control and its chilcontrols /// </summary> /// <param name="secondsElapsed"></param> /// <param name="cursorPoint"></param> public virtual void Update(double secondsElapsed, InputUtilities inputUtils, TVector2 cursorPoint, bool checkMouse = false) { bool canUpdate = this.visible; if (this.Parent != null) { if (!this.Parent.Visible) { canUpdate = false; } } if (canUpdate && checkMouse) { MouseEvent result = new MouseEvent() { Handled = false, Depth = 0 }; CheckMouseEvents(cursorPoint, inputUtils, ref result); } #region CHILDCONTROLS foreach (Control <TRenderer, TColor, TVector2, TFont> control in ChildControls) { control.Update(secondsElapsed, inputUtils, cursorPoint, false); } #endregion }
public override void Update(double secondsElapsed, InputUtilities keyUtils, SharpDX.Vector2 cursorPoint, bool checkMouse = false) { if (this.Parent != null) { this.Width = Parent.Width - this.MarginLeft - this.MarginRight - Parent.MarginLeft - Parent.MarginRight; } base.Update(secondsElapsed, keyUtils, cursorPoint, checkMouse); }
public override void UpdateControls(double secondsElapsed, InputUtilities keys) { Vector2 cursor = new Vector2(this.CursorPosition.X, this.CursorPosition.Y); foreach (ExternalUtilsCSharp.UI.Control <SharpDXRenderer, Color, Vector2, TextFormat> control in this.ChildControls) { control.Update(secondsElapsed, keys, cursor, true); } }
private bool TakeTurn() { if (m_CurrentMovementDirection == EMovementDirection.EMD_NONE || m_IsInputBlocked) { return(false); } return(m_ActorReference.Move(InputUtilities.GetMovementVectorFromDirection(m_CurrentMovementDirection))); }
public void TestInputUtilitiesGetKeyWithCorrectArgument() { //initialize mapping in constructor InputUtilities inputUtilities = new InputUtilities(); Keys keyToTest = InputUtilities.GetKey("ArrowUp"); Keys expectedKey = Keys.Up; Assert.AreEqual(expectedKey, keyToTest); }
private void UpdateInput() { if (_playerActionMap != null) { Vector2 input = new Vector2(_playerActionMap.V.PollAxis(WingsuitAction.LookHorizontal), _playerActionMap.V.PollAxis(WingsuitAction.LookVertical)); _input = InputUtilities.CircularizeInput(input); _mouseLook = _playerActionMap.V.PollButton(WingsuitAction.ActivateMouseLook) == ButtonState.Pressed; } }
void Update() { // if (Input.GetKeyDown(KeyCode.R)) { // Debug.Log("Recentering..."); // Valve.VR.OpenVR.System.ResetSeatedZeroPose(); // } if (_controllerList.ControllerIndices.Count > 0) { var controllerIndex = _controllerList.ControllerIndices[0]; var controller = SteamVR_Controller.Input(controllerIndex); //var rotation = controller.transform.rot; _pitch = 0f; _roll = 0f; // TODO This provides spatial input for pilot pitch/roll // We don't use it at the moment because it sucks // What we want is a direct mapping from absolute rotation on the vive controller // to absolute position of the pilot. // var touchClick = controller.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad); // var touchClickDown = controller.GetTouchDown(EVRButtonId.k_EButton_SteamVR_Touchpad); // if (touchClickDown) { // _neutralRotation = controller.transform.rot; // } // if (touchClick && _neutralRotation.HasValue && controller.hasTracking) { // //var localRotation = Quaternion.Inverse(_neutralRotation.Value) * controller.transform.rot; //// Debug.Log("controller rotation: " + rotation.eulerAngles //// + " local rotation: " + localRotation.eulerAngles //// + " has tracking: " + controller.hasTracking //// + " touch click: " + touchClickDown); // // Vector3 baseForward = _neutralRotation.Value * Vector3.forward; // Vector3 baseRight = _neutralRotation.Value * Vector3.right; // Vector3 viveForward = rotation * Vector3.forward; // Vector3 viveRight = rotation * Vector3.right; // // _pitch = -GetAxis(viveForward, baseForward, baseRight); // _roll = GetAxis(viveRight, baseRight, baseForward); // // // pitch *= 1f - Mathf.Abs(Vector3.Dot(viveForward, baseRight)); // } var touchAxis = controller.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); touchAxis = Adapters.ApplyDeadzone(0.16f, touchAxis); touchAxis = InputUtilities.CircularizeInput(touchAxis); touchAxis = MathUtils.ScaleQuadratically(touchAxis, 2f); _pitch = touchAxis.y; _roll = touchAxis.x; Debug.Log("pitch " + _pitch + ", roll " + _roll); } }
public HolonomicDriveValues TankDrive(float left, float right, bool inputsSquared = false) { left = InputUtilities.TransformWithWarning(left, square: inputsSquared); right = InputUtilities.TransformWithWarning(right, square: inputsSquared); return(new HolonomicDriveValues { FrontLeft = left, FrontRight = right, RearLeft = left, RearRight = right }); }
public override void Update() { constraint.ForEachGameObject((egoComponent, movementInput) => { float horizontal = Input.GetAxisRaw(movementInput.HorizontalAxis); float vertical = Input.GetAxisRaw(movementInput.VerticalAxis); EgoEvents <SetVelocityByEvent> .AddEvent(new SetVelocityByEvent(egoComponent, new Vector2(horizontal, vertical))); Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); float theta = InputUtilities.AngleBetween(egoComponent.transform.position, cursorPos); EgoEvents <RotateToEvent> .AddEvent(new RotateToEvent(egoComponent, theta)); } ); }
public override void Update(double secondsElapsed, InputUtilities keyUtils, SharpDX.Vector2 cursorPoint, bool checkMouse = false) { base.Update(secondsElapsed, keyUtils, cursorPoint, checkMouse); if (this.Visible) { this.ContentLayout.ApplyLayout(this); float width = 0, height = 0; Control <SharpDXRenderer, Color, Vector2, TextFormat> lastControl = null; for (int i = 0; i < this.ChildControls.Count; i++) { var control = this.ChildControls[i]; if (!control.Visible) { continue; } lastControl = control; if (this.DynamicWidth) { if (control.Width + control.MarginLeft + control.MarginRight > width) { width = control.Width + control.MarginLeft + control.MarginRight; } } } if (this.DynamicHeight) { if (ChildControls.Count(x => x.Visible) > 0) { height = ChildControls.Where(x => x.Visible).Max(x => x.Y + x.Height); } } //if (lastControl != null) // height = lastControl.Y + lastControl.Height + lastControl.MarginBottom; if (this.DynamicWidth) { this.Width = width + this.MarginLeft + this.MarginRight; } if (this.DynamicHeight) { this.Height = height + this.MarginBottom; } } else { this.Height = 0; } }
public static void Main(string[] args) { Console.WriteLine("ADA Program"); GlobalDb.SetValue(MiniDb.PredefinedKeys.Name, InputUtilities.GetResponse("Please enter your name: ")); Console.WriteLine($"Hello {GlobalDb.GetValue(MiniDb.PredefinedKeys.Name)}!"); new Menu().InitiateMenu(); // var numbers = // InputUtilities.GetResponseArray("Please enter a list of numbers separated by a ',' to sum together."); // // Console.WriteLine("Answer: " + SumOfNumbers(numbers)); }
public override void Update(double secondsElapsed, InputUtilities inputUtils, SharpDX.Vector2 cursorPoint, bool checkMouse = false) { base.Update(secondsElapsed, inputUtils, cursorPoint, checkMouse); if (TabHeaders == null) { return; } float maxHeight = TabHeaders.Max(x => x.Height); this.Height = ChildControls[this.SelectedIndex].Height + maxHeight; this.ChildControls[this.SelectedIndex].Y = maxHeight; this.Width = TabHeaders[TabHeaders.Length - 1].X + TabHeaders[TabHeaders.Length - 1].Width; }
public void TestThatNamedOemKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.OemComma, (ConsoleModifiers)0).Should().Be(','); InputUtilities.TryGetSingleChar(ConsoleKey.OemComma, ConsoleModifiers.Shift).Should().Be('<'); InputUtilities.TryGetSingleChar(ConsoleKey.OemMinus, (ConsoleModifiers)0).Should().Be('-'); InputUtilities.TryGetSingleChar(ConsoleKey.OemMinus, ConsoleModifiers.Shift).Should().Be('_'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPeriod, (ConsoleModifiers)0).Should().Be('.'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPeriod, ConsoleModifiers.Shift).Should().Be('>'); InputUtilities.TryGetSingleChar(ConsoleKey.OemPlus, (ConsoleModifiers)0).Should().Be('='); InputUtilities.TryGetSingleChar(ConsoleKey.OemPlus, ConsoleModifiers.Shift).Should().Be('+'); }
public HolonomicDriveValues MecanumDrive(HolonomicDriveTrain driveTrain, float x, float y, bool inputsSquared = false) { x = InputUtilities.TransformWithWarning(x, square: inputsSquared); y = InputUtilities.TransformWithWarning(y, square: inputsSquared); var desiredMovement = new DenseVector(new [] { x, y }); // var desiredMovement = new DenseVector(new [] { 1f, 0f }); HolonomicDriveValues result = new HolonomicDriveValues(); result.FrontLeft = ComputeMecanumDriveMotorSpeed(desiredMovement, driveTrain.FrontLeft.GetComponent <VectorComponent>(DeviceComponentType.DriveWheelForceVector)); result.FrontRight = ComputeMecanumDriveMotorSpeed(desiredMovement, driveTrain.FrontRight.GetComponent <VectorComponent>(DeviceComponentType.DriveWheelForceVector)); result.RearLeft = ComputeMecanumDriveMotorSpeed(desiredMovement, driveTrain.RearLeft.GetComponent <VectorComponent>(DeviceComponentType.DriveWheelForceVector)); result.RearRight = ComputeMecanumDriveMotorSpeed(desiredMovement, driveTrain.RearRight.GetComponent <VectorComponent>(DeviceComponentType.DriveWheelForceVector)); return(result); }
public void TestThatDigitKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.D3, (ConsoleModifiers)0).Should().Be('3'); InputUtilities.TryGetSingleChar(ConsoleKey.D0, ConsoleModifiers.Shift).Should().Be(')'); InputUtilities.TryGetSingleChar(ConsoleKey.D1, ConsoleModifiers.Shift).Should().Be('!'); InputUtilities.TryGetSingleChar(ConsoleKey.D2, ConsoleModifiers.Shift).Should().Be('@'); InputUtilities.TryGetSingleChar(ConsoleKey.D3, ConsoleModifiers.Shift).Should().Be('#'); InputUtilities.TryGetSingleChar(ConsoleKey.D4, ConsoleModifiers.Shift).Should().Be('$'); InputUtilities.TryGetSingleChar(ConsoleKey.D5, ConsoleModifiers.Shift).Should().Be('%'); InputUtilities.TryGetSingleChar(ConsoleKey.D6, ConsoleModifiers.Shift).Should().Be('^'); InputUtilities.TryGetSingleChar(ConsoleKey.D7, ConsoleModifiers.Shift).Should().Be('&'); InputUtilities.TryGetSingleChar(ConsoleKey.D8, ConsoleModifiers.Shift).Should().Be('*'); InputUtilities.TryGetSingleChar(ConsoleKey.D9, ConsoleModifiers.Shift).Should().Be('('); }
private static KeyValuePair <ConsoleKeyInfo, ConsoleInputOperation> CreatePair( ConsoleKey key, ConsoleModifiers modifiers, ConsoleInputOperation op) { var c = InputUtilities.TryGetSingleChar(key, modifiers); var keyInfo = new ConsoleKeyInfo( c.GetValueOrDefault('\0'), key, modifiers.HasFlag(ConsoleModifiers.Shift), modifiers.HasFlag(ConsoleModifiers.Alt), modifiers.HasFlag(ConsoleModifiers.Control)); return(new KeyValuePair <ConsoleKeyInfo, ConsoleInputOperation>(keyInfo, op)); }
public override void Update(double secondsElapsed, InputUtilities keyUtils, SharpDX.Vector2 cursorPoint, bool checkMouse = false) { base.Update(secondsElapsed, keyUtils, cursorPoint, checkMouse); if (listen) { if (skip > 0) { skip--; return; } WinAPI.VirtualKeyShort[] buttons = keyUtils.Keys.KeysThatWentUp(); if (buttons.Length > 0) { Key = buttons[0]; listen = false; } } }
public override EMovementDirection TickInput() { int horizontalAxis = Mathf.CeilToInt(UnityEngine.Input.GetAxisRaw("Horizontal")); int verticalAxis = Mathf.CeilToInt(UnityEngine.Input.GetAxisRaw("Vertical")); // Calculating how much time the player has been holding the axis // This way the player can move by holding a key instead of having to press it every time if (horizontalAxis != 0 || verticalAxis != 0) { m_HoldingInputTime += Time.deltaTime; } // Effectively Processing which movement has to be made if ( // Player pressed something (UnityEngine.Input.GetButtonDown("Horizontal") || UnityEngine.Input.GetButtonDown("Vertical")) || // or has been holding for enough time m_HoldingInputTime > km_HoldingTimeToAct ) { m_HoldingInputTime = 0f; // Horizontal Axis have movement priority over Vertical Axis // This cannot be handled in one line because it is needed to ensure player cannot move diagonally if (horizontalAxis != 0) { m_MovementDirection = InputUtilities.GetMovementDirectionFromVector(new Vector2(horizontalAxis, 0)); } else { m_MovementDirection = InputUtilities.GetMovementDirectionFromVector(new Vector2(0, verticalAxis)); } } else { m_MovementDirection = EMovementDirection.EMD_NONE; } return(m_MovementDirection); }
// Update is called once per frame void Update() { bool aTouch = false; Vector3 touchPos = new Vector3(); InputUtilities.GetMouseInput(out aTouch, out touchPos); if (aTouch) { if (ClickedBody == null) // If we have not clicked on a body yet { Vector3 mousePos = touchPos; mousePos = Camera.main.ScreenToWorldPoint(mousePos); ClickedBody = lpMan.TestPointForBody(mousePos.x, mousePos.y); } } else { ClickedBody = null; } }
public void TestThatNumberedOemKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.Oem1, (ConsoleModifiers)0).Should().Be(';'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem1, ConsoleModifiers.Shift).Should().Be(':'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem2, (ConsoleModifiers)0).Should().Be('/'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem2, ConsoleModifiers.Shift).Should().Be('?'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem3, (ConsoleModifiers)0).Should().Be('`'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem3, ConsoleModifiers.Shift).Should().Be('~'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem4, (ConsoleModifiers)0).Should().Be('['); InputUtilities.TryGetSingleChar(ConsoleKey.Oem4, ConsoleModifiers.Shift).Should().Be('{'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem5, (ConsoleModifiers)0).Should().Be('\\'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem5, ConsoleModifiers.Shift).Should().Be('|'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem6, (ConsoleModifiers)0).Should().Be(']'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem6, ConsoleModifiers.Shift).Should().Be('}'); InputUtilities.TryGetSingleChar(ConsoleKey.Oem7, (ConsoleModifiers)0).Should().Be('\''); InputUtilities.TryGetSingleChar(ConsoleKey.Oem7, ConsoleModifiers.Shift).Should().Be('\"'); }
private static InputMap <WingsuitAction, float> CreateControllerAxisInput( InputSourceMapping <WingsuitAction> inputMapping, InputSettings inputSettings, Peripherals.ControllerPeripheral peripheral) { var controllerAxisSourceMap = peripheral.Axes; var inputWithJoystickAxisSource = inputMapping.ApplyMapping(controllerAxisSourceMap, Adapters.MergeAxes); // Circularize input of pitch and roll if both are mapped to a joystick if (new [] { WingsuitAction.PitchUp, WingsuitAction.PitchDown, WingsuitAction.RollLeft, WingsuitAction.RollRight }.All(inputWithJoystickAxisSource.Keys.Contains)) { var pitchUp = inputWithJoystickAxisSource.Source[WingsuitAction.PitchUp]; var pitchDown = inputWithJoystickAxisSource.Source[WingsuitAction.PitchDown]; var rollLeft = inputWithJoystickAxisSource.Source[WingsuitAction.RollLeft]; var rollRight = inputWithJoystickAxisSource.Source[WingsuitAction.RollRight]; Func <Vector2> circularizedInput = () => InputUtilities.CircularizeInput(new Vector2(rollRight() - rollLeft(), pitchUp() - pitchDown())); inputWithJoystickAxisSource = inputWithJoystickAxisSource.Source .SetItem(WingsuitAction.PitchUp, () => Adapters.FilterPositiveInput(circularizedInput().y)) .SetItem(WingsuitAction.PitchDown, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().y))) .SetItem(WingsuitAction.RollLeft, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().x))) .SetItem(WingsuitAction.RollRight, () => Adapters.FilterPositiveInput(circularizedInput().x)) .ToInputMap(); } // Scale all pitch, roll and yaw input of a joystick inputWithJoystickAxisSource = inputWithJoystickAxisSource.Adapt <WingsuitAction, float, float>((id, pollFn) => { if (PilotBodyMovementActions.Contains(id)) { return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, inputSettings.InputGamma))); } else if (PilotArmMovementActions.Contains(id)) { return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, 2))); } return(pollFn); }); return(inputWithJoystickAxisSource); }
public void TestThatAlphaKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.E, (ConsoleModifiers)0).Should().Be('e'); InputUtilities.TryGetSingleChar(ConsoleKey.E, ConsoleModifiers.Shift).Should().Be('E'); InputUtilities.TryGetSingleChar(ConsoleKey.E, ConsoleModifiers.Control).Should().Be('\x05'); }
public override void Update(double secondsElapsed, InputUtilities keyUtils, Vector2 cursorPoint, bool checkMouse = false) { this.LastCursorPoint = cursorPoint; base.Update(secondsElapsed, keyUtils, cursorPoint, checkMouse); }
private void LogKey(ConsoleKeyInfo key) { var x = ConsoleOutput.CursorLeft; var y = ConsoleOutput.CursorTop; var fgColor = ConsoleOutput.ForegroundColor; var bgColor = ConsoleOutput.BackgroundColor; try { ConsoleOutput.SetCursorPosition(0, 0); ConsoleOutput.ForegroundColor = ConsoleColor.Yellow; ConsoleOutput.BackgroundColor = ConsoleColor.DarkBlue; var builder = new StringBuilder(); builder.AppendFormat("[Key: {{{0, -12}}}] ", key.Key); if (char.IsControl(key.KeyChar)) { builder.AppendFormat("[Char: 0x{0:X}] ", (int)key.KeyChar); } else if (key.KeyChar != (char)0) { builder.AppendFormat("[Char: '{0}' : 0x{1:X}] ", key.KeyChar, (int)key.KeyChar); } var modifiers = (ConsoleModifiers)0; var translationModifiers = (ConsoleModifiers)0; var modifierNames = new List <string>(); if (key.Modifiers.HasFlag(ConsoleModifiers.Control)) { modifiers |= ConsoleModifiers.Control; modifierNames.Add("Ctrl"); } if (key.Modifiers.HasFlag(ConsoleModifiers.Alt)) { modifiers |= ConsoleModifiers.Alt; modifierNames.Add("Alt"); } if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) { modifiers |= ConsoleModifiers.Shift; translationModifiers |= ConsoleModifiers.Shift; } var translatedToChars = false; if (modifiers.HasFlag(ConsoleModifiers.Alt) || modifiers.HasFlag(ConsoleModifiers.Control)) { var chars = InputUtilities.GetChars(key.Key, translationModifiers); if (chars.Length > 0) { var charsAsString = new string(chars); builder.AppendFormat("[{0}+{1}]", string.Join("+", modifierNames), charsAsString); translatedToChars = true; } } if (!translatedToChars) { if (key.Modifiers.HasFlag(ConsoleModifiers.Shift)) { modifierNames.Add("Shift"); } if (modifierNames.Count > 0) { builder.AppendFormat("[{0}+{1}]", string.Join("+", modifierNames), key.Key); } } if (builder.Length < ConsoleOutput.BufferWidth) { builder.Append(new string(' ', ConsoleOutput.BufferWidth - builder.Length)); } ConsoleOutput.Write(builder.ToString()); } finally { ConsoleOutput.ForegroundColor = fgColor; ConsoleOutput.BackgroundColor = bgColor; ConsoleOutput.SetCursorPosition(x, y); } }
public void TestThatWhitespaceKeysTranslateCorrectly() { InputUtilities.TryGetSingleChar(ConsoleKey.Spacebar, (ConsoleModifiers)0).Should().Be(' '); InputUtilities.TryGetSingleChar(ConsoleKey.Tab, (ConsoleModifiers)0).Should().Be('\t'); }