The Xbox One gamepad is equipped with A, B, X, Y, Back and Start buttons; left and right sticks; left and right bumpers; D-pad; two vibration motors; and two impulse triggers for creating various vibration effects. This topic describes the basics of programming the Xbox One gamepad.
This overview assumes that you are familiar with how to use the gamepad API, as described in Getting Started with the Gamepad API.
These buttons report their state as either up or down: A, B, X, Y, Back, Start, left and right sticks, left and right bumpers, and D-up, D-down, D-left, D-right. Up means released; down means pressed.
To check whether a button is pressed, use the appropriate “IsPressed” function. For example, to check whether the A button is pressed, call IsAPressed.
C++
IVectorView<IGamepad^>^ gamepads = Gamepad::Gamepads;
// For simplicity, we assume there is only one connected Xbox One gamepad.
// Otherwise, check if the gamepads vector size is > 0 first, by using this: if (gamepads->Size > 0)
IGamepad^ gamepad0 = gamepads->GetAt(0);
IGamepadReading^ reading = gamepad0->GetCurrentReading();
if (reading->IsAPressed)
{
// Add game logic for A button pressed.
}
For more information about checking button state, see How to: Detect Whether a Gamepad Button Is Pressed.
Both left and right sticks have floating-point x-axis and y-axis values that vary from -1.0 to 1.0. Stick values are approximately zero when the stick is centered, and 1.0 at the extremes of stick motion. Call LeftThumbstickX and LeftThumbstickY to get the values for the left joystick, and call RightThumbstickX and RightThumbstickX to get the values of the right joystick.
C++
float leftStickX = reading->LeftThumbstickX; // Returns a value between -1.0 and 1.0.
float leftStickY = reading->LeftThumbstickY; // Returns a value between -1.0 and 1.0.
float rightStickX = reading->RightThumbstickX; // Returns a value between -1.0 and 1.0.
float rightStickY = reading->RightThumbstickY; // Returns a value between -1.0 and 1.0.
The two triggers return analog values between 0.0 (not depressed) and 1.0 (fully depressed). To get the left trigger value, call LeftTrigger. To get the right trigger value, call RightTrigger.
C++
float leftTrigger = reading->LeftTrigger; // Returns a value between 0.0 and 1.0.
float rightTrigger = reading->RightTrigger; // Returns a value between 0.0 and 1.0.
A new feature of the Xbox One gamepad is that the triggers can be made to produce various vibration effects; they are therefore referred to as impulse triggers. Your app might use this to give tactile feedback when the trigger has been activated. Your app code activates trigger vibrations by sending data that describes the desired vibration—the “trigger envelope”.
Call SetVibration to set the impulse triggers.
For details on how to program the impulse triggers and how to effectively use trigger envelopes, see Gamepad Vibration Overview.
The two vibration motors that vibrate the gamepad generate different effects. The left motor is for rough, high-amplitude vibrations, while the right motor is for more subtle vibrations. You can combine them to achieve different effects. To vibrate the motors, use SetVibration, as shown below:
C++
GamepadVibration vib;
vib.LeftMotorLevel = 0.75f; // Speed ranges from 0.0 and 1.0.
vib.RightMotorLevel = 0.75f; // Speed ranges from 0.0 and 1.0.
vib.LeftTriggerLevel: 0,
vib.rightTriggerLevel: 0
gamepad0->SetVibration(vib);
Vibration continues at the specified levels for approximately 2.5 seconds, or until you call the Gamepad.SetVibration Method again with new GamepadVibration Structure values.
The Gamepad sample contains several tests for you to interact with every button, every stick, every bumper, every vibration motor, and every impulse trigger. Build the Gamepad project and deploy it to the Xbox One development kit to begin programming the Xbox One gamepad.
Getting Started with the Gamepad API
How to: Activate the Gamepad Impulse Triggers
How to: Detect Whether a Gamepad Button Is Pressed
How to: Activate Controller Vibration
How to: Get the Pairing Between Bodies and Users by Using an Event-Driven Approach