Gamepad Gamepad Gamepad Gamepad Class
Definition
Represents a gamepad.
public : sealed class Gamepad : IGameController, IGameControllerBatteryInfo, IGamepad, IGamepad2public sealed class Gamepad : IGameController, IGameControllerBatteryInfo, IGamepad, IGamepad2Public NotInheritable Class Gamepad Implements IGameController, IGameControllerBatteryInfo, IGamepad, IGamepad2// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Remarks
Instances of the Gamepad class cannot be created directly; instead, instances of the Gamepad class are retrieved through the Gamepad.Gamepads property listing all connected gamepads or through the Gamepad.GamepadAdded event.
Supported Devices
Gamepad supports any Xbox One certified or Xbox 360 compatible gamepad.
Properties
Gamepads Gamepads Gamepads Gamepads
The list of all connected gamepads.
public : static IVectorView<Gamepad> Gamepads { get; }public static IReadOnlyList<Gamepad> Gamepads { get; }Public Static ReadOnly Property Gamepads As IReadOnlyList<Gamepad>// You can use this property in JavaScript.
- Value
- IVectorView<Gamepad> IReadOnlyList<Gamepad> IReadOnlyList<Gamepad> IReadOnlyList<Gamepad>
The list of all connected gamepads.
Headset Headset Headset Headset
The audio headset attached to the gamepad.
public : Headset Headset { get; }public Headset Headset { get; }Public ReadOnly Property Headset As Headset// You can use this property in JavaScript.
- See Also
IsWireless IsWireless IsWireless IsWireless
Gets a value that indicates the wireless state of the gamepad.
public : PlatForm::Boolean IsWireless { get; }public bool IsWireless { get; }Public ReadOnly Property IsWireless As bool// You can use this property in JavaScript.
- Value
- PlatForm::Boolean bool bool bool
True if the gamepad is wireless. Otherwise, false.
Vibration Vibration Vibration Vibration
Describes the gamepad motor speed.
public : GamepadVibration Vibration { get; set; }public GamepadVibration Vibration { get; set; }Public ReadWrite Property Vibration As GamepadVibration// You can use this property in JavaScript.
Describes the gamepad motor speed.
Methods
FromGameController(IGameController) FromGameController(IGameController) FromGameController(IGameController) FromGameController(IGameController)
Returns the given game controller as a gamepad.
public : static Gamepad FromGameController(IGameController gameController)public static Gamepad FromGameController(IGameController gameController)Public Static Function FromGameController(gameController As IGameController) As Gamepad// You can use this method in JavaScript.
- gameController
- IGameController IGameController IGameController IGameController
The game controller to be returned as a gamepad.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
Examples
In the following example, the app gets the first available RawGameController object, and tries to access this game controller via the Gamepad class:
Gamepad^ gamepad;
if (RawGameController::RawGameControllers->Size > 0)
{
RawGameController^ rawGameController = RawGameController::RawGameControllers->GetAt(0);
gamepad = Gamepad::FromGameController(rawGameController);
}
if (gamepad != nullptr)
{
// Assign a standard button mapping to this controller.
}
Remarks
This method checks if the provided game controller has a gamepad implementation, and if so, it returns that implementation. You might use this method if you want to first get the controller as a RawGameController, and then see if it can be used as a Gamepad—if so, you can use a default control scheme for gamepads, otherwise you can let the player do their own input mapping.
GetButtonLabel(GamepadButtons) GetButtonLabel(GamepadButtons) GetButtonLabel(GamepadButtons) GetButtonLabel(GamepadButtons)
Retrieves the button label for the specified button.
public : GameControllerButtonLabel GetButtonLabel(GamepadButtons button)public GameControllerButtonLabel GetButtonLabel(GamepadButtons button)Public Function GetButtonLabel(button As GamepadButtons) As GameControllerButtonLabel// You can use this method in JavaScript.
The button for which to retrieve the label.
The label for the specified button. If the button label is blank or there is no known label for the controller’s button, then None is returned.
| Device family |
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v3)
|
GetCurrentReading() GetCurrentReading() GetCurrentReading() GetCurrentReading()
Gets a snapshot of the gamepad state.
public : GamepadReading GetCurrentReading()public GamepadReading GetCurrentReading()Public Function GetCurrentReading() As GamepadReading// You can use this method in JavaScript.
The current state of the gamepad.
TryGetBatteryReport() TryGetBatteryReport() TryGetBatteryReport() TryGetBatteryReport()
Gets information about the gamepad's current battery state.
public : BatteryReport TryGetBatteryReport()public BatteryReport TryGetBatteryReport()Public Function TryGetBatteryReport() As BatteryReport// You can use this method in JavaScript.
Information about the arcade stick's current battery state.
| Device family |
Windows 10 Creators Update (introduced v10.0.15063.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v4)
|
Events
GamepadAdded GamepadAdded GamepadAdded GamepadAdded
Signals when a new gamepad is connected.
public : static event EventHandler GamepadAdded<Gamepad>public static event EventHandler GamepadAdded<Gamepad>Public Static Event GamepadAdded<Gamepad>// You can use this event in JavaScript.
Remarks
To identify controllers that have already been added, you query the list of conected controllers using Gamepad.Gamepads.
GamepadRemoved GamepadRemoved GamepadRemoved GamepadRemoved
Signals when a gamepad is disconnected.
public : static event EventHandler GamepadRemoved<Gamepad>public static event EventHandler GamepadRemoved<Gamepad>Public Static Event GamepadRemoved<Gamepad>// You can use this event in JavaScript.
HeadsetConnected HeadsetConnected HeadsetConnected HeadsetConnected
Signals when a headset is attached to the gamepad.
public : event TypedEventHandler HeadsetConnected<IGameController, Headset>public event TypedEventHandler HeadsetConnected<IGameController, Headset>Public Event HeadsetConnected<IGameController, Headset>// You can use this event in JavaScript.
HeadsetDisconnected HeadsetDisconnected HeadsetDisconnected HeadsetDisconnected
Signals when a headset is disconnected from the gamepad.
public : event TypedEventHandler HeadsetDisconnected<IGameController, Headset>public event TypedEventHandler HeadsetDisconnected<IGameController, Headset>Public Event HeadsetDisconnected<IGameController, Headset>// You can use this event in JavaScript.
UserChanged UserChanged UserChanged UserChanged
Signals when the user associated with the gamepad has changed.
public : event TypedEventHandler UserChanged<IGameController, UserChangedEventArgs>public event TypedEventHandler UserChanged<IGameController, UserChangedEventArgs>Public Event UserChanged<IGameController, UserChangedEventArgs>// You can use this event in JavaScript.