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.axes
Read only- An array representing the controls with axes present on the device (e.g. analog thumb sticks).
Gamepad.buttons
Read only- An array of
gamepadButton
objects representing the buttons present on the device. Gamepad.connected
Read only- A boolean indicating whether the gamepad is still connected to the system.
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.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.
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 |
Gamepad Extensions The definition of 'Gamepad extensions' in that specification. |
Editor's Draft | Defines the Experimental extensions to Gamepad |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Gamepad | Chrome
Full support
35
| Edge Full support ≤18 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
Gamepad() constructor | Chrome Full support 35 | Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera Full support 22 | Safari Full support 10.1 | WebView Android No support No | Chrome Android Full support 35 | Firefox Android Full support 32 | Opera Android Full support 22 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 4.0 |
axes | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
buttons | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
connected | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
hand | Chrome No support No | Edge No support 15 — 79 | Firefox
Full support
Yes
| IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
hapticActuators | Chrome No support No | Edge No support 15 — 79 | Firefox
Full support
Yes
| IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
id | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari No support No | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS No support No | Samsung Internet Android
Full support
4.0
|
index | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
mapping | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
timestamp | Chrome
Full support
35
| Edge Full support 12 | Firefox
Full support
29
| IE No support No | Opera
Full support
22
| Safari Full support 10.1 | WebView Android No support No | Chrome Android
Full support
35
| Firefox Android Full support 32 | Opera Android
Full support
22
| Safari iOS Full support 10.3 | Samsung Internet Android
Full support
4.0
|
vibrationActuator | Chrome Full support 68 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 55 | Safari No support No | WebView Android No support No | Chrome Android Full support 68 | Firefox Android No support No | Opera Android Full support 48 | Safari iOS No support No | Samsung Internet Android Full support 10.0 |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.
- Requires a vendor prefix or different name for use.