这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

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.

句法

 var gamepads = navigator.getGamepads();
					

范例

window.addEventListener("gamepadconnected", function(e) {
  var gp = navigator.getGamepads()[e.gamepad.index];
  console.log(
    "Gamepad connected at index %d: %s. %d buttons, %d axes.",
    gp.index, gp.id, gp.buttons.length, gp.axes.length
  );
});
					

规范

规范 状态 注释
Gamepad
The definition of 'The Gamepad API specification' in that specification.
工作草案 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getGamepads Chrome 35
35
21 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 29 IE No Opera 22
22
15 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari No WebView Android 37
37
Yes Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android 35
35
25 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android No Opera Android 22
22
14 Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS No Samsung Internet Android 3.0
3.0
1.5 Prefixed
Prefixed Implemented with the vendor prefix: webkit

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: