Use the Gamepad API to get gamepad state and determine when the A button is pressed.
This overview assumes that you are familiar with how to use Visual Studio to create your first app, as described in Your First Application.
Your app’s project file should include a reference to windows.winmd.
For ease in using the Gamepad API namespace, add the following lines to the source code file where you plan to handle gamepad input.
C++
using namespace Windows::Xbox::Input;
using namespace Windows::Foundation::Collections;
At any one time, the Xbox One supports eight physical controllers (USB and wireless combined). This includes gamepads, wheels, fight sticks, or other physical devices. Devices that attach to the controller port, such as the Xbox One Headset, or SmartGlass devices, do not count against the 8 physical device total. BodyControllers also do not count towards this limit.
Note When more than three controllers are connected through USB (one per physical USB port), powered hubs must be used. One hub should be connected to the side USB port, and another hub to one of the back USB ports on the console.
In your app code, in a function that you call periodically to poll inputs, use Gamepad::Gamepads to get a list of gamepads. Enumerate that list, and poll each Gamepad for its current readings with Gamepad::GetCurrentReading. In the sample framework used for Xbox One samples, the appropriate function for polling inputs is Game::Update(float totalTime, float elapsedTime). The following code shows how to modify that function in a sample so that it checks to see if the A button is pressed.
Note GamePad::GetCurrentReading can return stale values from the controller if your title simultaneously over-utilizes cores 4 and 5. This is because the system worker threads running in the background to receive packets from the controller are always scheduled to run on cores 4 and 5. These worker threads have normal priority so that they do not interfere with your title code. You can use PIX’s System Monitor tool to inspect your title’s thread utilization. If this is an issue for your game, you can use the new Manual Controller Update APIs to schedule when and where input updates occur. This allows you to choose on which core the updates occur, rather than relying on the system to schedule the updates automatically.
C++
void Game::Update(float totalTime, float elapsedTime)
{
IVectorView<IGamepad^>^ gamepads = Gamepad::GetGamepads();
for ( unsigned int i = 0; i < gamepads->Size; ++i )
{
IGamepadReading^ reading = gamepads->GetAt(i)->GetCurrentReading();
if ( reading->IsAPressed )
{
// Add your game logic for A button pressed.
}
}
// Add your additional game logic here.
}
The thumbsticks on the Xbox One Gamepads have an average deadzone value of 0.24f. Tighter (lower value) deadzone values can be used as desired by the application.