The Gamepad interface of the Gamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id.
A Gamepad object can be returned in one of two ways: via the gamepad property of the gamepadconnected and gamepaddisconnected events, or by grabbing any position in the array returned by the Navigator.getGamepads() method.
Properties
- Gamepad.displayIdRead only
- Returns the VRDisplay.displayIdof an associatedVRDisplay(if relevant) — theVRDisplaythat the gamepad is controlling the displayed scene of.
- Gamepad.idRead only
- A DOMStringcontaining identifying information about the controller.
- Gamepad.indexRead only
- An integer that is auto-incremented to be unique for each device currently connected to the system.
- Gamepad.mappingRead only
- A string indicating whether the browser has remapped the controls on the device to a known layout.
- Gamepad.connectedRead only
- A boolean indicating whether the gamepad is still connected to the system.
- Gamepad.buttonsRead only
- An array of gamepadButtonobjects representing the buttons present on the device.
- Gamepad.axesRead only
- An array representing the controls with axes present on the device (e.g. analog thumb sticks).
- Gamepad.timestampRead only
- A DOMHighResTimeStamprepresenting the last time the data for this gamepad was updated.
Experimental extensions to Gamepad
The following interfaces are defined in the Gamepad Extensions specification, and provide access to experimental features like haptic feedback and WebVR controller pose information.
- Gamepad.handRead only
- An enum defining what hand the controller is being held in, or is most likely to be held in.
- Gamepad.hapticActuatorsRead only
- An array containing GamepadHapticActuatorobjects, each of which represents haptic feedback hardware available on the controller.
- Gamepad.poseRead only
- A GamepadPoseobject representing the pose information associated with a WebVR controller (e.g. its position and orientation in 3D space).
Example
window.addEventListener("gamepadconnected", function(e) {
  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  e.gamepad.index, e.gamepad.id,
  e.gamepad.buttons.length, e.gamepad.axes.length);
});
Specifications
| Specification | Status | Comment | 
|---|---|---|
| Gamepad The definition of 'Gamepad' in that specification. | Working Draft | Initial definition | 
| WebVR 1.1 The definition of 'displayId' in that specification. | Editor's Draft | Defines the Gamepad.displayIdproperty. | 
| Gamepad Extensions The definition of 'Gamepad extensions' in that specification. | Editor's Draft | Defines the Experimental extensions to Gamepad | 
Browser compatibility
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) | 
|---|---|---|---|---|---|---|
| General support | 21.0 webkit 35.0 | (Yes) | 29.0 (29.0) | No support | 15.0 webkit 22.0 | No support | 
| displayId | (Yes) | No support | 56 (56) | No support | No support | No support | 
| Gamepad extensions | No support | No support | No support[1] | No support | No support | No support | 
| Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | 
|---|---|---|---|---|---|---|
| General support | No support | ? | 32.0 (32.0) | No support | No support | No support | 
| displayId | No support | No support | 56.0 (56) | No support | No support | No support | 
| Gamepad extensions | No support | No support | No support[1] | No support | No support | No support | 
[1] Enabled in Firefox Nightly and Beta, versions 55 and above. Enabled/disabled by the dom.gamepad-extensions.enabled pref.