protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) { if (args.Button == JoystickButton.FirstHatUp + hatIndex) { upBox.FadeOut(100); } else if (args.Button == JoystickButton.FirstHatDown + hatIndex) { downBox.FadeOut(100); } else if (args.Button == JoystickButton.FirstHatLeft + hatIndex) { leftBox.FadeOut(100); } else if (args.Button == JoystickButton.FirstHatRight + hatIndex) { rightBox.FadeOut(100); } else { return(base.OnJoystickRelease(state, args)); } return(true); }
private void Joystick_InputReceived(object sender, JoystickEventArgs e) { if (e.Button == 0 && e.IsPressed) // Front button { drone.Hover(); } else if (e.Button == 1 && e.IsPressed) // Pad-2 button { drone.Emergency(); } else if (e.Button == 2 && e.IsPressed) // Pad-3 button { drone.Takeoff(); } else if (e.Button == 4 && e.IsPressed) // Pad-5 button { drone.Land(); } else if (e.Button == 9 && e.IsPressed) // Throttle-10 button { heightMaintainer.TargetHeight += 0.25f; // meter } else if (e.Button == 10 && e.IsPressed) // Throttle-11 button { heightMaintainer.TargetHeight -= 0.25f; // meter } }
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) { if (args.Button != button) { return(base.OnJoystickRelease(state, args)); } background.FadeOut(100); return(true); }
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) { if (args.Button != button) { return(base.OnJoystickPress(state, args)); } background.FadeIn(100, Easing.OutQuint); return(true); }
public bool AxisMoved(JoystickEventArgs arg, int axis) { int axisValue = arg.State.Axis[axis].Absolute; if (axisValue > 2500 || axisValue < -2500) { log.Info(String.Format("Joystick AxisMoved : {0} = {1} )", axis, axisValue)); } return(true); }
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) { if (args.Button == positiveAxisButton || args.Button == negativeAxisButton) { background.FadeColour(new Color4(0, 0, 0, 0), 100, Easing.OutQuint); } else { return(base.OnJoystickRelease(state, args)); } return(true); }
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) { if (args.Button == positiveAxisButton) { background.FadeColour(Color4.DarkGreen, 100, Easing.OutQuint); } else if (args.Button == negativeAxisButton) { background.FadeColour(Color4.DarkRed, 100, Easing.OutQuint); } else { return(base.OnJoystickPress(state, args)); } return(true); }
private bool DoButtonClick(int offset, MDI.JoystickUpdate entry) { var eventArgs = new JoystickEventArgs(this, JoystickState); if ((entry.Value & 0x80) != 0) { JoystickState.Buttons |= offset; if (IsBuffered && EventListener != null) { return(EventListener.ButtonPressed(eventArgs, 0)); } } else { JoystickState.Buttons &= ~offset; if (IsBuffered && EventListener != null) { return(EventListener.ButtonReleased(eventArgs, 0)); } } return(true); }
private void Js_InputReceived(object sender, JoystickEventArgs e) { if (e.IsButtonEvent) { if (e.Button == 0 && e.IsPressed) // Front button { Client.Hover(); } else if (e.Button == 1 && e.IsPressed) // Pad-2 button { Client.Emergency(); } else if (e.Button == 2 && e.IsPressed) // Pad-3 button { Client.Takeoff(); } else if (e.Button == 4 && e.IsPressed) // Pad-5 button { Client.Land(); } } }
void Joystick_InputReceived(object sender, JoystickEventArgs e) { if (j.ButtonStates.Count <= 8 || j.AxisValues.Count <= 1) { return; } if (j.ButtonStates[7]) { yaw = 0.5f; } else if (j.ButtonStates[8]) { yaw = -0.5f; } else { yaw = 0; } roll = j.AxisValues[0]; }
protected override void OnJoystickConnected(JoystickEventArgs e) { base.OnJoystickConnected(e); }
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) => AllowUserPresses && base.OnJoystickRelease(state, args);
public bool PovMoved(JoystickEventArgs arg, int pov) { log.Info(String.Format("Joystick PovMoved : {0} = {1} )", pov, arg.State.Povs[pov].Direction.ToString())); return(true); }
public bool SliderMoved(JoystickEventArgs arg, int slider) { log.Info(String.Format("Joystick SliderMoved : {0} = {1}, {2} )", slider, arg.State.Sliders[slider].X, arg.State.Sliders[slider].Y)); return(true); }
private void JoystickRight_OnJoystickReleased(object sender, JoystickEventArgs e) { Debug.WriteLine("JSR Released"); SetJoyStickValue(new JoyStickValues(null, 0, 0, null)); }
/// <summary> /// 被动模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _joystick_P_Click(object sender, JoystickEventArgs e) { if (JoystickRunningMode == JoystickRunningModeType.ReceiveOnly) { //检测方向键 int x = 0, y = 0; if ((e.Buttons & JoystickButtons.UP) == JoystickButtons.UP) { y--; } if ((e.Buttons & JoystickButtons.Down) == JoystickButtons.Down) { y++; } if ((e.Buttons & JoystickButtons.Left) == JoystickButtons.Left) { x--; } if ((e.Buttons & JoystickButtons.Right) == JoystickButtons.Right) { x++; } if (x == -1 && y == -1) { OnJoystickPressEvent(JoystickButtonType.TopLeft); } if (x == 0 && y == -1) { OnJoystickPressEvent(JoystickButtonType.TopCenter); } if (x == 1 && y == -1) { OnJoystickPressEvent(JoystickButtonType.TopRight); } if (x == -1 && y == 0) { OnJoystickPressEvent(JoystickButtonType.MiddleLeft); } if (x == 0 && y == 0) { OnJoystickPressEvent(JoystickButtonType.MiddleCenter); } if (x == 1 && y == 0) { OnJoystickPressEvent(JoystickButtonType.MiddleRight); } if (x == -1 && y == 1) { OnJoystickPressEvent(JoystickButtonType.BottomLeft); } if (x == 0 && y == 1) { OnJoystickPressEvent(JoystickButtonType.BottomCenter); } if (x == 1 && y == 1) { OnJoystickPressEvent(JoystickButtonType.BottomRight); } //检查B1-B10的按键 if ((e.Buttons & JoystickButtons.B1) == JoystickButtons.B1) { OnJoystickPressEvent(JoystickButtonType.B1); } else if ((e.Buttons & JoystickButtons.B2) == JoystickButtons.B2) { OnJoystickPressEvent(JoystickButtonType.B2); } else if ((e.Buttons & JoystickButtons.B3) == JoystickButtons.B3) { OnJoystickPressEvent(JoystickButtonType.B3); } else if ((e.Buttons & JoystickButtons.B4) == JoystickButtons.B4) { OnJoystickPressEvent(JoystickButtonType.B4); } else if ((e.Buttons & JoystickButtons.B5) == JoystickButtons.B5) { OnJoystickPressEvent(JoystickButtonType.B5); } else if ((e.Buttons & JoystickButtons.B6) == JoystickButtons.B6) { OnJoystickPressEvent(JoystickButtonType.B6); } else if ((e.Buttons & JoystickButtons.B7) == JoystickButtons.B7) { OnJoystickPressEvent(JoystickButtonType.B7); } else if ((e.Buttons & JoystickButtons.B8) == JoystickButtons.B8) { OnJoystickPressEvent(JoystickButtonType.B8); } else if ((e.Buttons & JoystickButtons.B9) == JoystickButtons.B9) { OnJoystickPressEvent(JoystickButtonType.B9); } else if ((e.Buttons & JoystickButtons.B10) == JoystickButtons.B10) { OnJoystickPressEvent(JoystickButtonType.B10); } } }
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) => handleNewPressed(state, KeyCombination.FromJoystickButton(args.Button), false);
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) { Console.WriteLine(state); return(false); }
private void JoystickRight_OnJoystickMoved(object sender, JoystickEventArgs e) { Debug.WriteLine("JSR Moved"); SetJoyStickValue(new JoyStickValues(null, e.XValue, e.YValue, null)); }
void _joystick_P_Click(object sender, JoystickEventArgs e) { int x = 0, y = 0; if ((e.Buttons & JoystickButtons.UP) == JoystickButtons.UP) { y--; } if ((e.Buttons & JoystickButtons.Down) == JoystickButtons.Down) { y++; } if ((e.Buttons & JoystickButtons.Left) == JoystickButtons.Left) { x--; } if ((e.Buttons & JoystickButtons.Right) == JoystickButtons.Right) { x++; } if (x == -1 && y == -1) { this.lbl_Dirt.TextAlign = ContentAlignment.TopLeft; } if (x == 0 && y == -1) { this.lbl_Dirt.TextAlign = ContentAlignment.TopCenter; } if (x == 1 && y == -1) { this.lbl_Dirt.TextAlign = ContentAlignment.TopRight; } if (x == -1 && y == 0) { this.lbl_Dirt.TextAlign = ContentAlignment.MiddleLeft; } if (x == 0 && y == 0) { this.lbl_Dirt.TextAlign = ContentAlignment.MiddleCenter; } if (x == 1 && y == 0) { this.lbl_Dirt.TextAlign = ContentAlignment.MiddleRight; } if (x == -1 && y == 1) { this.lbl_Dirt.TextAlign = ContentAlignment.BottomLeft; } if (x == 0 && y == 1) { this.lbl_Dirt.TextAlign = ContentAlignment.BottomCenter; } if (x == 1 && y == 1) { this.lbl_Dirt.TextAlign = ContentAlignment.BottomRight; } this.lbl_1.BackColor = ((e.Buttons & JoystickButtons.B1) == JoystickButtons.B1) ? Color.Red : SystemColors.Control; this.lbl_2.BackColor = ((e.Buttons & JoystickButtons.B2) == JoystickButtons.B2) ? Color.Red : SystemColors.Control; this.lbl_3.BackColor = ((e.Buttons & JoystickButtons.B3) == JoystickButtons.B3) ? Color.Red : SystemColors.Control; this.lbl_4.BackColor = ((e.Buttons & JoystickButtons.B4) == JoystickButtons.B4) ? Color.Red : SystemColors.Control; this.lbl_5.BackColor = ((e.Buttons & JoystickButtons.B5) == JoystickButtons.B5) ? Color.Red : SystemColors.Control; this.lbl_6.BackColor = ((e.Buttons & JoystickButtons.B6) == JoystickButtons.B6) ? Color.Red : SystemColors.Control; this.lbl_7.BackColor = ((e.Buttons & JoystickButtons.B7) == JoystickButtons.B7) ? Color.Red : SystemColors.Control; this.lbl_8.BackColor = ((e.Buttons & JoystickButtons.B8) == JoystickButtons.B8) ? Color.Red : SystemColors.Control; this.lbl_9.BackColor = ((e.Buttons & JoystickButtons.B9) == JoystickButtons.B9) ? Color.Red : SystemColors.Control; }
public override void Capture() { if (_joyInfo.IsXInput) { CaptureXInput(); return; } MDI.JoystickUpdate[] bufferedData = null; bufferedData = this._joystick.GetBufferedData(); if (bufferedData == null) { this._joystick.Poll(); bufferedData = this._joystick.GetBufferedData(); if (bufferedData == null) { return; } } bool[] axisMoved = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }; bool[] sliderMoved = { false, false, false, false }; foreach (var entry in bufferedData) { switch (entry.Offset) { /* sliders */ case MDI.JoystickOffset.Sliders1: sliderMoved[0] = true; JoystickState.Sliders[0].X = entry.Value; break; case MDI.JoystickOffset.Sliders0: sliderMoved[0] = true; JoystickState.Sliders[0].Y = entry.Value; break; case MDI.JoystickOffset.PointOfViewControllers0: if (ChangePOV(0, entry)) { return; } break; case MDI.JoystickOffset.PointOfViewControllers1: if (ChangePOV(1, entry)) { return; } break; case MDI.JoystickOffset.PointOfViewControllers2: if (ChangePOV(2, entry)) { return; } break; case MDI.JoystickOffset.PointOfViewControllers3: if (ChangePOV(3, entry)) { return; } break; case MDI.JoystickOffset.VelocitySliders0: sliderMoved[1] = true; JoystickState.Sliders[1].X = entry.Value; break; case MDI.JoystickOffset.VelocitySliders1: sliderMoved[1] = true; JoystickState.Sliders[1].X = entry.Value; break; case MDI.JoystickOffset.AccelerationSliders0: sliderMoved[0] = true; JoystickState.Sliders[2].X = entry.Value; break; case MDI.JoystickOffset.AccelerationSliders1: sliderMoved[0] = true; JoystickState.Sliders[2].X = entry.Value; break; case MDI.JoystickOffset.ForceSliders0: sliderMoved[0] = true; JoystickState.Sliders[3].X = entry.Value; break; case MDI.JoystickOffset.ForceSliders1: sliderMoved[0] = true; JoystickState.Sliders[3].X = entry.Value; break; default: if (entry.Offset >= MDI.JoystickOffset.Buttons0 && entry.Offset < MDI.JoystickOffset.Buttons127) { if (!DoButtonClick((int)entry.Offset - (int)MDI.JoystickOffset.Buttons0, entry)) { return; } } else { } break; } } //Check to see if any of the axes values have changed.. if so send events if ((IsBuffered == true) && (EventListener != null) && bufferedData.Length > 0) { JoystickEventArgs temp = new JoystickEventArgs(this, JoystickState); //Update axes for (int i = 0; i < axisMoved.Length; i++) { if (axisMoved[i]) { if (EventListener.AxisMoved(temp, i) == false) { return; } } } //Now update sliders for (int i = 0; i < 4; i++) { if (sliderMoved[i]) { if (EventListener.SliderMoved(temp, i) == false) { return; } } } } }
private void DirectionControl_OnJoystickMoved(object sender, JoystickEventArgs e) { XValue.Content = e.X.ToString(); YValue.Content = e.Y.ToString(); }
private void CaptureXInput() { var controller = new SXI.Controller((SXI.UserIndex)_joyInfo.XInputDevice); var inputState = controller.GetState(); bool[] axisMoved = { false, false, false, false, false, false, false, false }; //AXIS axisMoved[0] = GetAxisMovement(JoystickState.Axis[0], -inputState.Gamepad.LeftThumbY); axisMoved[1] = GetAxisMovement(JoystickState.Axis[1], inputState.Gamepad.LeftThumbX); axisMoved[2] = GetAxisMovement(JoystickState.Axis[2], -inputState.Gamepad.RightThumbY); axisMoved[3] = GetAxisMovement(JoystickState.Axis[3], inputState.Gamepad.RightThumbX); axisMoved[4] = GetAxisMovement(JoystickState.Axis[4], inputState.Gamepad.LeftTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.LeftTrigger * 129 : Joystick.Max_Axis); axisMoved[5] = GetAxisMovement(JoystickState.Axis[5], inputState.Gamepad.RightTrigger * 129 < Joystick.Max_Axis ? inputState.Gamepad.RightTrigger * 129 : Joystick.Max_Axis); //POV Pov.Position previousPov = JoystickState.Povs[0].Direction; Pov.Position pov = Pov.Position.Centered; if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadUp) != 0) { pov |= Pov.Position.North; } else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadDown) != 0) { pov |= Pov.Position.South; } if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadLeft) != 0) { pov |= Pov.Position.West; } else if ((inputState.Gamepad.Buttons & SXI.GamepadButtonFlags.DPadRight) != 0) { pov |= Pov.Position.East; } JoystickState.Povs[0].Direction = pov; //BUTTONS // Skip the first 4 as they are the DPad. var previousButtons = JoystickState.Buttons; for (int i = 0; i < 12; i++) { if (((int)inputState.Gamepad.Buttons & (1 << (i + 4))) != 0) { JoystickState.Buttons |= 1 << (i + 4); } else { JoystickState.Buttons &= ~(1 << (i + 4)); } } //Send Events if (IsBuffered && EventListener != null) { var joystickEvent = new JoystickEventArgs(this, JoystickState); // Axes for (int index = 0; index < axisMoved.Length; index++) { if (axisMoved[index] == true && EventListener.AxisMoved(joystickEvent, index)) { return; } } //POV if (previousPov != pov && !EventListener.PovMoved(joystickEvent, 0)) { return; } //Buttons for (int i = 4; i < 16; i++) { if (((previousButtons & (1 << i)) == 0) && JoystickState.IsButtonDown(i)) { if (!EventListener.ButtonPressed(joystickEvent, i)) { return; } } else if (((previousButtons & (1 << i)) != 0) && !JoystickState.IsButtonDown(i)) { if (!EventListener.ButtonReleased(joystickEvent, i)) { return; } } } } }
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) => handleNewReleased(state, KeyCombination.FromJoystickButton(args.Button));
public bool ButtonReleased(JoystickEventArgs arg, int button) { log.Info(String.Format("Joystick ButtonReleased : {0} )", button)); return(true); }