手柄 API

手柄 API is a way for developers to access and respond to signals from gamepads and other game controllers in a simple, consistent way. It contains three interfaces, two events and one specialist function, to respond to gamepads being connected and disconnected, and to access other information about the gamepads themselves, and what buttons and other controls are currently being pressed.

接口

Gamepad
Represents a gamepad/controller connected to the computer.
GamepadButton
Represents a button on one of the connected controllers.
GamepadEvent
The event object representing events fired that are related to gamepads.

Experimental Gamepad extensions

GamepadHapticActuator
Represents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware.
GamepadPose
Represents the pose of a controller (e.g. position and orientation in 3D space) in the case of a WebVR controller. This is not used by the newer WebXR 标准。

另请参阅 extensions to the Gamepad interface , for features that allow you to access the above information.

Extensions to other interfaces

Navigator.getGamepads()
An extension to the Navigator object that returns an array of Gamepad objects, one for each connected gamepad.

Window events

Window.ongamepadconnected
Represents an event handler that will run when a gamepad is connected (when the gamepadconnected event fires).
Window.ongamepaddisconnected
Represents an event handler that will run when a gamepad is disconnected (when the gamepaddisconnected event fires).

Tutorials and guides

规范

规范 状态 Comment
Gamepad Extensions 编者草案 Defines the Experimental Gamepad extensions .
Gamepad
The definition of 'The Gamepad API specification' 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
Gamepad 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Gamepad() 构造函数 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 35 Firefox Android 32 Opera Android 22 Safari iOS 10.3 Samsung Internet Android 4.0
axes 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
buttons 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
connected Chrome 35
35
不支持 25 — 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
displayId
弃用
Chrome ? — 80
Disabled
不支持 ? — 80
Disabled
Only works on desktop in an experimental version of Chrome (other builds won't return any devices when Navigator.getVRDisplays() is invoked).
Disabled Until version 80 (exclusive): this feature is behind the WebVR preference. To change preferences in Chrome, visit chrome://flags.
Edge 15 Firefox 55
55
Windows support was enabled in Firefox 55.
64
macOS support was enabled in Firefox 64.
IE No Opera ? Safari No WebView Android No Chrome Android ? — 80
不支持 ? — 80
Currently supported only by Google Daydream.
Firefox Android 55 Opera Android ? Safari iOS No Samsung Internet Android Yes
Yes
Currently supported only by Google Daydream.
hand
Chrome No Edge 15 — 79 Firefox Yes
Disabled
Yes
Disabled
The flag is enabled by default in Firefox Nightly and Beta, versions 55 and above.
Disabled This feature is behind the dom.gamepad-extensions.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
hapticActuators
Chrome No Edge 15 — 79 Firefox Yes
Disabled
Yes
Disabled
The flag is enabled by default in Firefox Nightly and Beta, versions 55 and above.
Disabled This feature is behind the dom.gamepad-extensions.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
id
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 No WebView Android No Chrome Android 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS No Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
index
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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
mapping 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
pose
Chrome No Edge 15 — 79 Firefox Yes
Disabled
Yes
Disabled
The flag is enabled by default in Firefox Nightly and Beta, versions 55 and above.
Disabled This feature is behind the dom.gamepad-extensions.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
timestamp 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 35
35
不支持 25 — 34
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android 32 Opera Android 22
22
不支持 14 — 21
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS 10.3 Samsung Internet Android 4.0
4.0
不支持 2.0 — 3.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit
vibrationActuator
非标
Chrome 68 Edge 79 Firefox No IE No Opera 55 Safari No WebView Android No Chrome Android 68 Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android 10.0

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅