Navigator: getGamepads() method
The Navigator.getGamepads()
method returns an array of Gamepad
objects, one for each gamepad connected to the device.
Elements in the array may be null
if a gamepad disconnects during a session, so that the remaining gamepads retain the same index.
Syntax
Parameters
Return value
An Array
of Gamepad
objects, eventually empty.
Exceptions
Examples
window.addEventListener("gamepadconnected", (e) => {
const gp = navigator.getGamepads()[e.gamepad.index];
console.log(
`Gamepad connected at index ${gp.index}: ${gp.id} with ${gp.buttons.length} buttons, ${gp.axes.length} axes.`,
);
});
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
getGamepads |
3521 |
12 |
29 |
No |
2215 |
10.1 |
37≤37 |
3525 |
32 |
2214 |
10.3 |
3.01.5 |
secure_context_required |
86 |
86 |
91 |
No |
72 |
No |
No |
86 |
No |
No |
No |
No |
See also