public XInputButton(GamepadButtonFlags f) { ButtonFlag = f; IsAnalog = false; Index = ButtonFlag == 0 ? 0 : (int)Math.Pow(2, 1.0 / (int)ButtonFlag); Name = f.ToString(); }
/// <summary> /// Returns the currently pressed buttons on the XInput controller as an array of buttons. /// </summary> public bool[] GetButtons() { // Create the array of buttons. bool[] buttons = new bool[Enum.GetNames(typeof(ControllerButtonsGeneric)).Length]; // Get XBOX Buttons GamepadButtonFlags buttonFlags = ControllerState.Gamepad.Buttons; // Retrieve Controller Button Status. buttons[(int)ControllerButtonsGeneric.ButtonA] = buttonFlags.HasFlag(GamepadButtonFlags.A); buttons[(int)ControllerButtonsGeneric.ButtonB] = buttonFlags.HasFlag(GamepadButtonFlags.B); buttons[(int)ControllerButtonsGeneric.ButtonX] = buttonFlags.HasFlag(GamepadButtonFlags.X); buttons[(int)ControllerButtonsGeneric.ButtonY] = buttonFlags.HasFlag(GamepadButtonFlags.Y); buttons[(int)ControllerButtonsGeneric.ButtonLs] = buttonFlags.HasFlag(GamepadButtonFlags.LeftThumb); buttons[(int)ControllerButtonsGeneric.ButtonRs] = buttonFlags.HasFlag(GamepadButtonFlags.RightThumb); buttons[(int)ControllerButtonsGeneric.ButtonLb] = buttonFlags.HasFlag(GamepadButtonFlags.LeftShoulder); buttons[(int)ControllerButtonsGeneric.ButtonRb] = buttonFlags.HasFlag(GamepadButtonFlags.RightShoulder); buttons[(int)ControllerButtonsGeneric.ButtonBack] = buttonFlags.HasFlag(GamepadButtonFlags.Back); buttons[(int)ControllerButtonsGeneric.ButtonStart] = buttonFlags.HasFlag(GamepadButtonFlags.Start); buttons[(int)ControllerButtonsGeneric.ButtonGuide] = false; // Return buttons. return(buttons); }
/// <summary> /// Add binary/button type mapping. /// </summary> /// <param name="deadZone">Used when source is range/axis type.</param> public Map(string value, GamepadButtonFlags flag, string deadZone) { Target = TargetType.Button; Load(value); ButtonFlag = flag; int.TryParse(deadZone, out DeadZone); }
/// <summary> /// Updates the internal state based on what the controller observes. /// </summary> public void UpdateState() { State gamepadState = controller.GetState(); if (gamepadState.PacketNumber == lastState.PacketNumber) { // No gamepad delta return; } // Set the button booleans if there have been rising-edge events. GamepadButtonFlags flags = gamepadState.Gamepad.Buttons; CheckButton(GamepadButtonFlags.X, flags, ref xPressed); CheckButton(GamepadButtonFlags.Y, flags, ref yPressed); CheckButton(GamepadButtonFlags.A, flags, ref aPressed); CheckButton(GamepadButtonFlags.B, flags, ref bPressed); CheckButton(GamepadButtonFlags.LeftShoulder, flags, ref leftBumperPressed); CheckButton(GamepadButtonFlags.RightShoulder, flags, ref rightBumperPressed); CheckButton(GamepadButtonFlags.DPadLeft, flags, ref leftPadPressed); CheckButton(GamepadButtonFlags.DPadRight, flags, ref rightPadPressed); CheckButton(GamepadButtonFlags.DPadUp, flags, ref upPadPressed); CheckButton(GamepadButtonFlags.DPadDown, flags, ref downPadPressed); CheckButton(GamepadButtonFlags.Start, flags, ref startPressed); UpdateSticks(gamepadState); lastState = gamepadState; }
private void UpdateStickAndShoulderButtons(GamepadButtonFlags buttons) { UpdateButton(buttons, GamepadButtonFlags.LeftShoulder, GamePadButton.LeftShoulder); UpdateButton(buttons, GamepadButtonFlags.LeftThumb, GamePadButton.LeftStick); UpdateButton(buttons, GamepadButtonFlags.RightShoulder, GamePadButton.RightShoulder); UpdateButton(buttons, GamepadButtonFlags.RightThumb, GamePadButton.RightStick); }
public GameController(UserIndex index = UserIndex.Any) { _lastPressedButtons = GamepadButtonFlags.None; _controller = new Controller(index); Index = index; Deadband = GlobalDeadband; }
public bool GetBButton(GamepadButtonFlags flags) { if (flags.HasFlag(GamepadButtonFlags.B)) { return true; } return false; }
public XInputController() { controller = new Controller(UserIndex.One); connection = controller.IsConnected; leftBumper = GamepadButtonFlags.LeftShoulder; rightBumper = GamepadButtonFlags.RightShoulder; }
private void UpdateDPadButtons(GamepadButtonFlags buttons) { UpdateButton(buttons, GamepadButtonFlags.DPadDown, GamePadButton.Down); UpdateButton(buttons, GamepadButtonFlags.DPadUp, GamePadButton.Up); UpdateButton(buttons, GamepadButtonFlags.DPadLeft, GamePadButton.Left); UpdateButton(buttons, GamepadButtonFlags.DPadRight, GamePadButton.Right); }
public JoystickButtonTrigger(Core coordinator, XmlNode node) : base(coordinator, GetName(node, "Joystick Button Trigger")) { GamepadButtonFlags b = GamepadButtonFlags.A; if (Enum.TryParse<GamepadButtonFlags>(GetString(node, mButton.ToString(), "Button"), out b)) mButton = b; }
public bool GetDPadDownButton(GamepadButtonFlags flags) { if (flags.HasFlag(GamepadButtonFlags.DPadDown)) { return true; } return false; }
private float GetButtonValue(GamepadButtonFlags button) { if (currentState.Gamepad.Buttons.HasFlag(button)) { return(1); } return(0); }
public static Mapping Create(GamepadButtonFlags control, Action response) { Mapping m = new Mapping(); m.Control = control; m.Response = response; return(m); }
private void UpdateButton(GamepadButtonFlags buttons, GamepadButtonFlags nativeButton, GamePadButton button) { var buttonIndex = (int)button; states[buttonIndex] = states[buttonIndex].UpdateOnNativePressing((buttons & nativeButton) != 0); }
internal GameControllerStateDPad(GamepadButtonFlags flags) { Up = flags.HasFlag(GamepadButtonFlags.DPadUp); Down = flags.HasFlag(GamepadButtonFlags.DPadDown); Left = flags.HasFlag(GamepadButtonFlags.DPadLeft); Right = flags.HasFlag(GamepadButtonFlags.DPadRight); AnyInteraction = (int)flags > 0 && (int)flags < 16; }
private void OnInputChanged(object sender, EventArgs e) { m_currentInput = (InputsMgr.eInputName)GameBoy.Parameters.inputName; if (m_currentInput != eInputName.e_inputName_none) { if (m_currentInput == eInputName.e_inputName_keyboard) { m_k_up = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputUp); m_k_down = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputDown); m_k_left = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputLeft); m_k_right = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputRight); m_k_A = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputA); m_k_B = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputB); m_k_start = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputStart); m_k_select = (Key)KeyInterop.KeyFromVirtualKey((int)GameBoy.Parameters.inputSelect); } else { UserIndex i = UserIndex.Any; switch (m_currentInput) { case InputsMgr.eInputName.e_inputName_gamepad_1: { i = UserIndex.One; break; } case InputsMgr.eInputName.e_inputName_gamepad_2: { i = UserIndex.Two; break; } case InputsMgr.eInputName.e_inputName_gamepad_3: { i = UserIndex.Three; break; } case InputsMgr.eInputName.e_inputName_gamepad_4: { i = UserIndex.Four; break; } } m_gamepad = new Xbox360Controller.Gamepad360(i); m_p_up = (GamepadButtonFlags)GameBoy.Parameters.inputUp; m_p_down = (GamepadButtonFlags)GameBoy.Parameters.inputDown; m_p_left = (GamepadButtonFlags)GameBoy.Parameters.inputLeft; m_p_right = (GamepadButtonFlags)GameBoy.Parameters.inputRight; m_p_A = (GamepadButtonFlags)GameBoy.Parameters.inputA; m_p_B = (GamepadButtonFlags)GameBoy.Parameters.inputB; m_p_start = (GamepadButtonFlags)GameBoy.Parameters.inputStart; m_p_select = (GamepadButtonFlags)GameBoy.Parameters.inputSelect; } } }
public static Mapping Create(GamepadButtonFlags control, MouseAction response, Action.MouseOption option) { Mapping m = new Mapping(); m.Control = control; m.Response = response; (m.Response as MouseAction).Option = option; return(m); }
public static Mapping Create(GamepadButtonFlags control, ButtonAction response, VirtualKeyCode key) { Mapping m = new Mapping(); m.Control = control; m.Response = response; (m.Response as ButtonAction).Key = key; return(m); }
private void UpdateNormalButtons(GamepadButtonFlags buttons) { UpdateButton(buttons, GamepadButtonFlags.A, GamePadButton.A); UpdateButton(buttons, GamepadButtonFlags.B, GamePadButton.B); UpdateButton(buttons, GamepadButtonFlags.X, GamePadButton.X); UpdateButton(buttons, GamepadButtonFlags.Y, GamePadButton.Y); UpdateButton(buttons, GamepadButtonFlags.Back, GamePadButton.Back); UpdateButton(buttons, GamepadButtonFlags.Start, GamePadButton.Start); }
public ImageInfo(int image, MapCode code, double x, double y, Control label, Control control, GamepadButtonFlags button = GamepadButtonFlags.None) { Image = image; Label = label; Control = control; Button = button; Code = code; X = x; Y = y; }
public JoystickButtonTrigger(Core coordinator, XmlNode node) : base(coordinator, GetName(node, "Joystick Button Trigger")) { GamepadButtonFlags b = GamepadButtonFlags.A; if (Enum.TryParse <GamepadButtonFlags>(GetString(node, mButton.ToString(), "Button"), out b)) { mButton = b; } }
private bool IsDown(GamepadButtonFlags button, bool repeated) { if (repeated) { return((CurrButtonState & button) != 0); } else { return((CurrButtonState & button) != 0 && (LastButtonState & button) == 0); } }
private void HandleButton(GamepadButtonFlags buttonFlag, TextBox txt) { var button = new XInputButton { IsButton = true, ButtonCode = (short)buttonFlag }; txt.Text = buttonFlag.ToString(); txt.Tag = button; }
public XiButtonProcessor(InputDescriptor inputDescriptor, EventHandler observerListEmptyEventHandler, EventHandler <InputReportEventArgs> bindModeHandler) { _observerListEmptyEventHandler = observerListEmptyEventHandler; OnBindMode += bindModeHandler; _inputDescriptor = inputDescriptor; var index = inputDescriptor.BindingDescriptor.Type == BindingType.Button ? inputDescriptor.BindingDescriptor.Index : inputDescriptor.BindingDescriptor.SubIndex + 10; _gamepadButtonFlag = _buttonFlags[index]; }
private bool CheckButtonPressed(GamepadButtonFlags button) { if (firstUpdate) { return(false); } bool current = currentState.Gamepad.Buttons.HasFlag(button); bool last = lastState.Gamepad.Buttons.HasFlag(button); return(current && !last); }
internal void Update() { IsConnected = Model.IsConnected; if (!IsConnected) { return; } var next = Model.GetState(); changedButtons = current.Gamepad.Buttons ^ next.Gamepad.Buttons; current = next; }
private void CheckButton(GamepadButtonFlags button, GamepadButtonFlags newFlags, ref bool flagToTrigger) { GamepadButtonFlags lastFlags = lastState.Gamepad.Buttons; if (newFlags.HasFlag(button)) { if (!lastFlags.HasFlag(button)) { flagToTrigger = true; } } }
private static EInputButton GetInputButtonFromXInput(GamepadButtonFlags xinputButton) { switch (xinputButton) { case GamepadButtonFlags.None: return(EInputButton.Unknown); case GamepadButtonFlags.DPadUp: return(EInputButton.DPadUp); case GamepadButtonFlags.DPadDown: return(EInputButton.DPadUp); case GamepadButtonFlags.DPadLeft: return(EInputButton.DPadLeft); case GamepadButtonFlags.DPadRight: return(EInputButton.DPadRight); case GamepadButtonFlags.Start: return(EInputButton.Start); case GamepadButtonFlags.Back: return(EInputButton.Options); case GamepadButtonFlags.LeftThumb: return(EInputButton.LeftThumb); case GamepadButtonFlags.RightThumb: return(EInputButton.RightThumb); case GamepadButtonFlags.LeftShoulder: return(EInputButton.LeftShoulder); case GamepadButtonFlags.RightShoulder: return(EInputButton.RightShoulder); case GamepadButtonFlags.A: return(EInputButton.ControllerActionDown); case GamepadButtonFlags.B: return(EInputButton.ControllerActionRight); case GamepadButtonFlags.X: return(EInputButton.ControllerActionLeft); case GamepadButtonFlags.Y: return(EInputButton.ControllerActionUp); } return(EInputButton.Unknown); }
public static GamepadButtonFlags sortButtons(State state) { for (int i = 0; i < priority.Length; i++) { GamepadButtonFlags flg = priority[i]; if (isPressed(ref state, flg)) { return(flg); } } return(GamepadButtonFlags.Start);//return start button as default not in the list }
private Mapping GetMappingFor(GamepadButtonFlags control) { Mapping temp = null; foreach (Mapping m in _controlMapping) { if (m.Control.ToString() == control.ToString()) { temp = m; } } return(temp); }
private static Dictionary <string, bool> ParseButtonFlagsToDictionary(GamepadButtonFlags buttonFlags) { var result = new Dictionary <string, bool>(); foreach (short button in Enum.GetValues(typeof(GamepadButtonFlags))) { if (button != (short)GamepadButtonFlags.None) { result.Add(Enum.GetName(typeof(GamepadButtonFlags), button), ((short)buttonFlags & button) != 0); } } return(result); }
private void HandleButton(GamepadButtonFlags buttonFlag, TextBox txt, int index) { var button = new XInputButton { IsButton = true, ButtonCode = (short)buttonFlag, XInputIndex = index }; var t = txt.Tag as JoystickButtons; txt.Text = $"Input Device {index} " + buttonFlag; t.BindNameXi = txt.Text; t.XInputButton = button; }
void DrawState(GamepadButtonFlags button, Point location, Label label, PaintEventArgs e) { var mW = -this.markB.Width / 2; var mH = -this.markB.Height / 2; var on = gamePadState.Gamepad.Buttons.HasFlag(button); if (on) { e.Graphics.DrawImage(this.markB, location.X + mW, location.Y + mH); } if (label != null) { setLabelColor(on, label); } }
void DrawState(GamepadButtonFlags button, Point location, Label label, PaintEventArgs e) { var mW = -this.markB.Width / 2; var mH = -this.markB.Height / 2; var on = gamePadState.Gamepad.Buttons.HasFlag(button); if (on) e.Graphics.DrawImage(this.markB, location.X + mW, location.Y + mH); if (label != null) setLabelColor(on, label); }
private static Buttons AddButtonIfPressed(Buttons originalButtonState, GamepadButtonFlags buttonFlags, GamepadButtonFlags xInputButton, Buttons xnaButton) { return GamePad.ConvertToButtonState(buttonFlags, xInputButton) == ButtonState.Pressed ? originalButtonState | xnaButton : originalButtonState; }
public void DrawButton(Vector2 centerPos, GamepadButtonFlags button) { switch (button) { case GamepadButtonFlags.Y: ButtonSprites[3].Draw(centerPos.Offset(-ButtonRectangle.Center)); break; case GamepadButtonFlags.B: ButtonSprites[1].Draw(centerPos.Offset(-ButtonRectangle.Center)); break; case GamepadButtonFlags.X: ButtonSprites[2].Draw(centerPos.Offset(-ButtonRectangle.Center)); break; case GamepadButtonFlags.A: ButtonSprites[0].Draw(centerPos.Offset(-ButtonRectangle.Center)); break; } }
public bool WasButtonPressed(GamepadButtonFlags button) { return !WasButtonDown(button) && IsButtonDown(button); }
public bool WasButtonDown(GamepadButtonFlags button) { return previousState.Gamepad.Buttons.HasFlag(button); }
public GamepadEventArgs(GamepadButtonFlags inButton, Boolean inIsDown) { Button = inButton; IsDown = inIsDown; }
private void checkButtonState(Controller controller, UserIndex userIndex, Gamepad oldState, GamepadButtonFlags button) { Gamepad currentState = controller.GetState().Gamepad; if ((oldState.Buttons & button) != (currentState.Buttons & button)) { if ((currentState.Buttons & button) != 0) { buttonPressed(controller, userIndex, button); } else { buttonReleased(controller, userIndex, button); } } }
private bool IsPressed(GamepadButtonFlags button) { return (GamepadManager.Gamepad.Buttons & button) == button; }
private static GamePadDPad ConvertToGamePadDPad(GamepadButtonFlags buttonFlags) { return new GamePadDPad(GamePad.ConvertToButtonState(buttonFlags, GamepadButtonFlags.DPadUp), GamePad.ConvertToButtonState(buttonFlags, GamepadButtonFlags.DPadDown), GamePad.ConvertToButtonState(buttonFlags, GamepadButtonFlags.DPadLeft), GamePad.ConvertToButtonState(buttonFlags, GamepadButtonFlags.DPadRight)); }
private Boolean Bit( GamepadButtonFlags set, GamepadButtonFlags check ) { Int32 s = ( Int32 )set; Int32 c = ( Int32 )check; return ( ( s & c ) == c ); }
private void onButtonReleased(Controller controller, UserIndex index, GamepadButtonFlags button) { mRepeatTimer.Stop(); if (mRepeatDelayTimer.Enabled) { mRepeatDelayTimer.Stop(); } mRepeatAction = null; }
private void onButtonPressed(Controller controller, UserIndex index, GamepadButtonFlags button) { Action repeatAction = null; switch (button) { case GamepadButtonFlags.DPadDown: repeatAction = new Action(navigateDown); break; case GamepadButtonFlags.DPadLeft: repeatAction = new Action(navigateLeft); break; case GamepadButtonFlags.DPadRight: repeatAction = new Action(navigateRight); break; case GamepadButtonFlags.DPadUp: repeatAction = new Action(navigateUp); break; case GamepadButtonFlags.A: mDispatcher.Invoke(new Action(trySelect)); break; case GamepadButtonFlags.B: mDispatcher.Invoke(new Action(leaveScreen)); break; } if (repeatAction != null) { mRepeatAction = repeatAction; mDispatcher.Invoke(mRepeatAction); if (!mRepeatTimer.Enabled && !mRepeatDelayTimer.Enabled) { mRepeatDelayTimer.Start(); } } }
public bool GetRightThumbDownButton(GamepadButtonFlags flags) { if (flags.HasFlag(GamepadButtonFlags.RightThumb)) { return true; } return false; }
private float GetButtonValue(GamepadButtonFlags button) { if (currentState.Gamepad.Buttons.HasFlag(button)) return 1; return 0; }
public bool GetRightShoulderButton(GamepadButtonFlags flags) { if (flags.HasFlag(GamepadButtonFlags.RightShoulder)) { return true; } return false; }
public bool IsButtonDown(GamepadButtonFlags button) { return currentState.Gamepad.Buttons.HasFlag(button); }
private static Buttons AddButtonIfPressed(Buttons originalButtonState, GamepadButtonFlags buttonFlags, GamepadButtonFlags xInputButton, Buttons xnaButton) { if (GamePad.ConvertToButtonState(buttonFlags, xInputButton) != ButtonState.Pressed) return originalButtonState; else return originalButtonState | xnaButton; }
private static ButtonState ConvertToButtonState(GamepadButtonFlags buttonFlags, GamepadButtonFlags desiredButton) { return buttonFlags.HasFlag((Enum) desiredButton) ? ButtonState.Pressed : ButtonState.Released; }
private bool CheckButtonPressed(GamepadButtonFlags button) { if (firstUpdate) return false; bool current = currentState.Gamepad.Buttons.HasFlag(button); bool last = lastState.Gamepad.Buttons.HasFlag(button); return current && !last; }
private static GamePadButtons ConvertToButtons(GamepadButtonFlags buttonFlags, short leftThumbX, short leftThumbY, short rightThumbX, short rightThumbY, byte leftTrigger, byte rightTrigger) { Buttons buttons1 = (Buttons) 0; for (int index = 0; index < GamePad.buttonMap.Count; ++index) { Tuple<GamepadButtonFlags, Buttons> tuple = GamePad.buttonMap[index]; buttons1 = GamePad.AddButtonIfPressed(buttons1, buttonFlags, tuple.Item1, tuple.Item2); } Buttons bitFieldToAddTo = GamePad.AddThumbstickButtons(leftThumbX, leftThumbY, (short) 7849, buttons1, Buttons.LeftThumbstickLeft, Buttons.LeftThumbstickRight, Buttons.LeftThumbstickUp, Buttons.LeftThumbstickDown); Buttons buttons2 = GamePad.AddThumbstickButtons(rightThumbX, rightThumbY, (short) 8689, bitFieldToAddTo, Buttons.RightThumbstickLeft, Buttons.RightThumbstickRight, Buttons.RightThumbstickUp, Buttons.RightThumbstickDown); if ((int) leftTrigger >= 30) buttons2 |= Buttons.LeftTrigger; if ((int) rightTrigger >= 30) buttons2 |= Buttons.RightTrigger; return new GamePadButtons(buttons2); }