MDN will be in maintenance mode on Friday September 22nd, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

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.displayId Read only
Returns the VRDisplay.displayId of an associated VRDisplay (if relevant) — the VRDisplay that the gamepad is controlling the displayed scene of.
Gamepad.id Read only
A DOMString containing identifying information about the controller.
Gamepad.index Read only
An integer that is auto-incremented to be unique for each device currently connected to the system.
Gamepad.mapping Read only
A string indicating whether the browser has remapped the controls on the device to a known layout.
Gamepad.connected Read only
A boolean indicating whether the gamepad is still connected to the system.
Gamepad.buttons Read only
An array of gamepadButton objects representing the buttons present on the device.
Gamepad.axes Read only
An array representing the controls with axes present on the device (e.g. analog thumb sticks).
Gamepad.timestamp Read only
A DOMHighResTimeStamp representing 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.hand Read only
An enum defining what hand the controller is being held in, or is most likely to be held in.
Gamepad.hapticActuators Read only
An array containing GamepadHapticActuator objects, each of which represents haptic feedback hardware available on the controller.
Gamepad.pose Read only
A GamepadPose object 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.displayId property.
Gamepad Extensions
The definition of 'Gamepad extensions' in that specification.
Editor's Draft Defines the Experimental extensions to Gamepad

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
axes

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
buttons

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
connected

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
displayId (Yes)2 3 (Yes)564 No ? ?
hand No Notrue6 7 No No No
hapticActuators No Notrue6 7 No No No
id

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
index

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
mapping

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
pose No Notrue6 7 No No No
timestamp

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
axes No (Yes) (Yes)32 No No No
buttons No (Yes) (Yes)32 No No No
connected No (Yes) (Yes)32 No No No
displayId No (Yes)5 ? ? No ? ?
hand No No No No No No No
hapticActuators No No No No No No No
id No (Yes) (Yes)32 No No No
index No (Yes) (Yes)32 No No No
mapping No (Yes) (Yes)32 No No No
pose No No No No No No No
timestamp No (Yes) (Yes)32 No No No

1. From version 24 until version 28 (exclusive): this feature is behind the dom.gamepad.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

2. Only works on desktop in an experimental version of Chrome (other builds won't return any devices when Navigator.getVRDisplays() is invoked).

3. , this feature is behind the WebVR preference. To change preferences in Chrome, visit chrome://flags.

4. Currently only Windows support is enabled by default. Mac support is available in Firefox Nightly.

5. Currently supported only by Google Daydream.

6. The flag is enabled by default in Firefox Nightly and Beta, versions 55 and above.

7. From version true, this feature is behind the dom.gamepad-extensions.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.

See also

Document Tags and Contributors

 Contributors to this page: fscholz, chrisdavidmills, codl, erikadoyle, teoli, Sebastianz, jsx
 Last updated by: fscholz,