GamepadEvent

The GamepadEvent interface of the Gamepad API contains references to gamepads connected to the system, which is what the gamepad events Window.gamepadconnected and Window.gamepaddisconnected are fired in response to.

构造函数

GamepadEvent()
返回新 GamepadEvent 对象。

特性

GamepadEvent.gamepad 只读
返回 Gamepad object, providing access to the associated gamepad data for the event fired.

范例

The gamepad property being called on a fired Window.gamepadconnected 事件。

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);
});
					

And on a Window.gamepaddisconnected 事件。

window.addEventListener("gamepaddisconnected", function(e) {
  console.log("Gamepad disconnected from index %d: %s",
  e.gamepad.index, e.gamepad.id);
});
					

规范

规范 状态 Comment
Gamepad
The definition of 'GamepadEvent' in that specification.
工作草案 初始定义

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
GamepadEvent Chrome 35
35
不支持 21 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge ≤18 Firefox 29
29
不支持 24 — 28
Disabled
Disabled 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.
IE No Opera 22
22
不支持 15 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 10.1 WebView Android No Chrome Android Yes Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android Yes
GamepadEvent() 构造函数 Chrome 35 Edge 12 Firefox 29
29
不支持 24 — 28
Disabled
Disabled 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.
IE No Opera 22 Safari 10.1 WebView Android No Chrome Android Yes Firefox Android 32 Opera Android 22 Safari iOS 10.3 Samsung Internet Android Yes
gamepad Chrome 35
35
不支持 21 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge 12 Firefox 29
29
不支持 24 — 28
Disabled
Disabled 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.
IE No Opera 22
22
不支持 15 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari 10.1 WebView Android No Chrome Android Yes Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
用户必须明确启用此特征。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅

Using the Gamepad API