public static Microsoft.Xna.Framework.Input.GamePadCapabilities GetCapabilities(PlayerIndex playerIndex) { var controller = GetController(playerIndex); if (!controller.IsConnected) return new Microsoft.Xna.Framework.Input.GamePadCapabilities(); // GamePadCapabilities.IsConnected = false by default var capabilities = controller.GetCapabilities(SharpDX.XInput.DeviceQueryType.Any); var ret = new Microsoft.Xna.Framework.Input.GamePadCapabilities(); switch (capabilities.SubType) { case SharpDX.XInput.DeviceSubType.ArcadePad: Debug.WriteLine("XInput's DeviceSubType.ArcadePad is not supported in XNA"); ret.GamePadType = Input.GamePadType.Unknown; // TODO: Should this be BigButtonPad? break; case SharpDX.XInput.DeviceSubType.ArcadeStick: ret.GamePadType = Input.GamePadType.ArcadeStick; break; case SharpDX.XInput.DeviceSubType.DancePad: ret.GamePadType = Input.GamePadType.DancePad; break; case SharpDX.XInput.DeviceSubType.DrumKit: ret.GamePadType = Input.GamePadType.DrumKit; break; case SharpDX.XInput.DeviceSubType.FlightStick: ret.GamePadType = Input.GamePadType.FlightStick; break; case SharpDX.XInput.DeviceSubType.Gamepad: ret.GamePadType = Input.GamePadType.GamePad; break; case SharpDX.XInput.DeviceSubType.Guitar: ret.GamePadType = Input.GamePadType.Guitar; break; case SharpDX.XInput.DeviceSubType.GuitarAlternate: ret.GamePadType = Input.GamePadType.AlternateGuitar; break; case SharpDX.XInput.DeviceSubType.GuitarBass: // Note: XNA doesn't distinguish between Guitar and GuitarBass, but // GuitarBass is identical to Guitar in XInput, distinguished only // to help setup for those controllers. ret.GamePadType = Input.GamePadType.Guitar; break; case SharpDX.XInput.DeviceSubType.Unknown: ret.GamePadType = Input.GamePadType.Unknown; break; case SharpDX.XInput.DeviceSubType.Wheel: ret.GamePadType = Input.GamePadType.Wheel; break; default: Debug.WriteLine("unexpected XInput DeviceSubType: {0}", capabilities.SubType.ToString()); ret.GamePadType = Input.GamePadType.Unknown; break; } var gamepad = capabilities.Gamepad; // digital buttons var buttons = gamepad.Buttons; ret.HasAButton = buttons.HasFlag(GBF.A); ret.HasBackButton = buttons.HasFlag(GBF.Back); ret.HasBButton = buttons.HasFlag(GBF.B); ret.HasBigButton = false; // TODO: what IS this? Is it related to GamePadType.BigGamePad? ret.HasDPadDownButton = buttons.HasFlag(GBF.DPadDown); ret.HasDPadLeftButton = buttons.HasFlag(GBF.DPadLeft); ret.HasDPadRightButton = buttons.HasFlag(GBF.DPadLeft); ret.HasDPadUpButton = buttons.HasFlag(GBF.DPadUp); ret.HasLeftShoulderButton = buttons.HasFlag(GBF.LeftShoulder); ret.HasLeftStickButton = buttons.HasFlag(GBF.LeftThumb); ret.HasRightShoulderButton = buttons.HasFlag(GBF.RightShoulder); ret.HasRightStickButton = buttons.HasFlag(GBF.RightThumb); ret.HasStartButton = buttons.HasFlag(GBF.Start); ret.HasXButton = buttons.HasFlag(GBF.X); ret.HasYButton = buttons.HasFlag(GBF.Y); // analog controls ret.HasRightTrigger = gamepad.LeftTrigger > 0; ret.HasRightXThumbStick = gamepad.RightThumbX != 0; ret.HasRightYThumbStick = gamepad.RightThumbY != 0; ret.HasLeftTrigger = gamepad.LeftTrigger > 0; ret.HasLeftXThumbStick = gamepad.LeftThumbX != 0; ret.HasLeftYThumbStick = gamepad.LeftThumbY != 0; // vibration bool hasForceFeedback = capabilities.Flags.HasFlag(SharpDX.XInput.CapabilityFlags.FfbSupported); ret.HasLeftVibrationMotor = hasForceFeedback && capabilities.Vibration.LeftMotorSpeed > 0; ret.HasRightVibrationMotor = hasForceFeedback && capabilities.Vibration.RightMotorSpeed > 0; // other ret.IsConnected = controller.IsConnected; ret.HasVoiceSupport = capabilities.Flags.HasFlag(SharpDX.XInput.CapabilityFlags.VoiceSupported); return ret; }
public GamepadCapabilities(int gamepadIndex) { if (gamepadIndex < 0 || gamepadIndex >= Input.MaxGamePads) { throw new System.ArgumentException($"Gamepad index '{gamepadIndex}' is out of valid range [0, {Input.MaxGamePads - 1}]"); } Microsoft.Xna.Framework.Input.GamePadCapabilities capabilities = Microsoft.Xna.Framework.Input.GamePad.GetCapabilities((Microsoft.Xna.Framework.PlayerIndex)gamepadIndex); Id = gamepadIndex; IsGamepadConnected = capabilities.IsConnected; Kind = (GamepadKind)((int)capabilities.GamePadType + ((int)GamepadKind.Unknown - (int)Microsoft.Xna.Framework.Input.GamePadType.Unknown)); #region Buttons AvailableButtons = XboxInputLabel.Buttons.None; if (capabilities.HasAButton) { AvailableButtons |= XboxInputLabel.Buttons.A; } if (capabilities.HasBButton) { AvailableButtons |= XboxInputLabel.Buttons.B; } if (capabilities.HasXButton) { AvailableButtons |= XboxInputLabel.Buttons.X; } if (capabilities.HasYButton) { AvailableButtons |= XboxInputLabel.Buttons.Y; } if (capabilities.HasLeftShoulderButton) { AvailableButtons |= XboxInputLabel.Buttons.LB; } if (capabilities.HasRightShoulderButton) { AvailableButtons |= XboxInputLabel.Buttons.RB; } if (capabilities.HasDPadUpButton) { AvailableButtons |= XboxInputLabel.Buttons.DUp; } if (capabilities.HasDPadRightButton) { AvailableButtons |= XboxInputLabel.Buttons.DRight; } if (capabilities.HasDPadDownButton) { AvailableButtons |= XboxInputLabel.Buttons.DDown; } if (capabilities.HasDPadLeftButton) { AvailableButtons |= XboxInputLabel.Buttons.DLeft; } if (capabilities.HasBackButton) { AvailableButtons |= XboxInputLabel.Buttons.Back; } if (capabilities.HasStartButton) { AvailableButtons |= XboxInputLabel.Buttons.Start; } if (capabilities.HasBigButton) { AvailableButtons |= XboxInputLabel.Buttons.BigButton; } #endregion Buttons #region Triggers AvailableTriggers = XboxInputLabel.Triggers.None; if (capabilities.HasLeftTrigger) { AvailableTriggers |= XboxInputLabel.Triggers.LT; } if (capabilities.HasRightTrigger) { AvailableTriggers |= XboxInputLabel.Triggers.RT; } #endregion Triggers #region Features AvailableFeatures = GamepadFeature.None; if (capabilities.HasLeftXThumbStick) { AvailableFeatures |= GamepadFeature.LeftThumbStickHorizontalAxis; } if (capabilities.HasLeftYThumbStick) { AvailableFeatures |= GamepadFeature.LeftThumbStickVerticalAxis; } if (capabilities.HasRightXThumbStick) { AvailableFeatures |= GamepadFeature.RightThumbStickHorizontalAxis; } if (capabilities.HasRightYThumbStick) { AvailableFeatures |= GamepadFeature.RightThumbStickVerticalAxis; } if (capabilities.HasLeftVibrationMotor) { AvailableFeatures |= GamepadFeature.LeftVibrationMotor; } if (capabilities.HasRightVibrationMotor) { AvailableFeatures |= GamepadFeature.RightVibrationMotor; } if (capabilities.HasVoiceSupport) { AvailableFeatures |= GamepadFeature.VoiceSupport; } if (capabilities.HasLightBarEXT) { AvailableFeatures |= GamepadFeature.LightBar; } if (capabilities.HasTriggerVibrationMotorsEXT) { AvailableFeatures |= GamepadFeature.TriggerVibrationMotors; } if (capabilities.HasMisc1EXT) { AvailableFeatures |= GamepadFeature.Misc1; } if (capabilities.HasPaddle1EXT) { AvailableFeatures |= GamepadFeature.Paddle1; } if (capabilities.HasPaddle2EXT) { AvailableFeatures |= GamepadFeature.Paddle2; } if (capabilities.HasPaddle3EXT) { AvailableFeatures |= GamepadFeature.Paddle3; } if (capabilities.HasPaddle4EXT) { AvailableFeatures |= GamepadFeature.Paddle4; } if (capabilities.HasTouchPadEXT) { AvailableFeatures |= GamepadFeature.TouchPad; } if (capabilities.HasGyroEXT) { AvailableFeatures |= GamepadFeature.Gyro; } if (capabilities.HasAccelerometerEXT) { AvailableFeatures |= GamepadFeature.Accelerometer; } #endregion Features }
public static Microsoft.Xna.Framework.Input.GamePadCapabilities GetCapabilities(PlayerIndex playerIndex) { var controller = GetController(playerIndex); if (!controller.IsConnected) { return(new Microsoft.Xna.Framework.Input.GamePadCapabilities()); // GamePadCapabilities.IsConnected = false by default } var capabilities = controller.GetCapabilities(SharpDX.XInput.DeviceQueryType.Any); var ret = new Microsoft.Xna.Framework.Input.GamePadCapabilities(); switch (capabilities.SubType) { case SharpDX.XInput.DeviceSubType.ArcadePad: Debug.WriteLine("XInput's DeviceSubType.ArcadePad is not supported in XNA"); ret.GamePadType = Input.GamePadType.Unknown; // TODO: Should this be BigButtonPad? break; case SharpDX.XInput.DeviceSubType.ArcadeStick: ret.GamePadType = Input.GamePadType.ArcadeStick; break; case SharpDX.XInput.DeviceSubType.DancePad: ret.GamePadType = Input.GamePadType.DancePad; break; case SharpDX.XInput.DeviceSubType.DrumKit: ret.GamePadType = Input.GamePadType.DrumKit; break; case SharpDX.XInput.DeviceSubType.FlightStick: ret.GamePadType = Input.GamePadType.FlightStick; break; case SharpDX.XInput.DeviceSubType.Gamepad: ret.GamePadType = Input.GamePadType.GamePad; break; case SharpDX.XInput.DeviceSubType.Guitar: ret.GamePadType = Input.GamePadType.Guitar; break; case SharpDX.XInput.DeviceSubType.GuitarAlternate: ret.GamePadType = Input.GamePadType.AlternateGuitar; break; case SharpDX.XInput.DeviceSubType.GuitarBass: // Note: XNA doesn't distinguish between Guitar and GuitarBass, but // GuitarBass is identical to Guitar in XInput, distinguished only // to help setup for those controllers. ret.GamePadType = Input.GamePadType.Guitar; break; case SharpDX.XInput.DeviceSubType.Unknown: ret.GamePadType = Input.GamePadType.Unknown; break; case SharpDX.XInput.DeviceSubType.Wheel: ret.GamePadType = Input.GamePadType.Wheel; break; default: Debug.WriteLine("unexpected XInput DeviceSubType: {0}", capabilities.SubType.ToString()); ret.GamePadType = Input.GamePadType.Unknown; break; } var gamepad = capabilities.Gamepad; // digital buttons var buttons = gamepad.Buttons; ret.HasAButton = buttons.HasFlag(GBF.A); ret.HasBackButton = buttons.HasFlag(GBF.Back); ret.HasBButton = buttons.HasFlag(GBF.B); ret.HasBigButton = false; // TODO: what IS this? Is it related to GamePadType.BigGamePad? ret.HasDPadDownButton = buttons.HasFlag(GBF.DPadDown); ret.HasDPadLeftButton = buttons.HasFlag(GBF.DPadLeft); ret.HasDPadRightButton = buttons.HasFlag(GBF.DPadLeft); ret.HasDPadUpButton = buttons.HasFlag(GBF.DPadUp); ret.HasLeftShoulderButton = buttons.HasFlag(GBF.LeftShoulder); ret.HasLeftStickButton = buttons.HasFlag(GBF.LeftThumb); ret.HasRightShoulderButton = buttons.HasFlag(GBF.RightShoulder); ret.HasRightStickButton = buttons.HasFlag(GBF.RightThumb); ret.HasStartButton = buttons.HasFlag(GBF.Start); ret.HasXButton = buttons.HasFlag(GBF.X); ret.HasYButton = buttons.HasFlag(GBF.Y); // analog controls ret.HasRightTrigger = gamepad.LeftTrigger > 0; ret.HasRightXThumbStick = gamepad.RightThumbX != 0; ret.HasRightYThumbStick = gamepad.RightThumbY != 0; ret.HasLeftTrigger = gamepad.LeftTrigger > 0; ret.HasLeftXThumbStick = gamepad.LeftThumbX != 0; ret.HasLeftYThumbStick = gamepad.LeftThumbY != 0; // vibration bool hasForceFeedback = capabilities.Flags.HasFlag(SharpDX.XInput.CapabilityFlags.FfbSupported); ret.HasLeftVibrationMotor = hasForceFeedback && capabilities.Vibration.LeftMotorSpeed > 0; ret.HasRightVibrationMotor = hasForceFeedback && capabilities.Vibration.RightMotorSpeed > 0; // other ret.IsConnected = controller.IsConnected; ret.HasVoiceSupport = capabilities.Flags.HasFlag(SharpDX.XInput.CapabilityFlags.VoiceSupported); return(ret); }