这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

 

Gamepad API 可以给予开发者一种简单、统一的方式来识别并响应游戏控制器(手柄)。其中包含了三个接口、两个事件、一个特殊函数,用来响应控制器的连接与断开、获取其他关于控制器的信息以及识别当前是哪个按键或是哪个控制器被按下了。

接口

Gamepad
表示已连接的游戏控制器。
GamepadButton
表示已连接手柄上的一个按键。
GamepadEvent
表示与控制器相关的事件的事件对象。

实验性 Gamepad 扩展

GamepadHapticActuator
表示控制器中的硬件,用于向用户提供触觉反馈(如果可用)最常见的是振动硬件。
GamepadPose
表示控制器的位置方向(例如, 在3D 空间中的位置和方向)于 WebVR 控制器中。

另请参阅  Gamepad 接口扩展,来获取上方的功能的相关信息。

其他接口扩展

Navigator.getGamepads()
Navigator 对象中的一个扩展。会返回一个 名为Gamepad 的数组对象,其中每个数组元素对应一个已连接的控制器。

Window 事件

Window.ongamepadconnected
表示当控制器连接时(当gamepadconnected 事件触发时)运行的处理程序。
Window.ongamepaddisconnected
表示当控制器断开连接时(当gamepaddisconnected 事件触发时)运行的处理程序。

教程与指南

规范

规范 状态 备注
Gamepad Extensions Editor's Draft Defines the Experimental Gamepad extensions.
Gamepad
The Gamepad API specification
Working Draft Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support YesFirefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes
Gamepad() constructorChrome Full support 35Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22Safari No support NoWebView Android No support NoChrome Android Full support 35Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22Safari iOS No support NoSamsung Internet Android Full support Yes
axesChrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes
buttonsChrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes
connectedChrome Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes
displayId
Experimental
Chrome Full support Yes
Notes Disabled
Full support Yes
Notes Disabled
Notes Only works on desktop in an experimental version of Chrome (other builds won't return any devices when Navigator.getVRDisplays() is invoked).
Disabled This feature is behind the WebVR preference. To change preferences in Chrome, visit chrome://flags.
Edge Full support 15Firefox Full support 56
Notes
Full support 56
Notes
Notes Currently only Windows support is enabled by default. Mac support is available in Firefox Nightly.
IE No support NoOpera ? Safari ? WebView Android No support NoChrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Currently supported only by Google Daydream.
Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
hand
Experimental
Chrome No support NoEdge Full support 15Firefox Full support Yes
Notes Disabled
Full support Yes
Notes Disabled
Notes 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 support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
hapticActuators
Experimental
Chrome No support NoEdge Full support 15Firefox Full support Yes
Notes Disabled
Full support Yes
Notes Disabled
Notes 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 support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
id
Experimental
Chrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
index
Experimental
Chrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
mappingChrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes
pose
Experimental
Chrome No support NoEdge Full support 15Firefox Full support Yes
Notes Disabled
Full support Yes
Notes Disabled
Notes 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 support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
timestampChrome Full support 35
Full support 35
No support 21 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Full support 12Firefox Full support 29
Full support 29
No support 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 support NoOpera Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari No support NoWebView Android No support NoChrome Android Full support 35
Full support 35
No support 25 — 34
Prefixed
Prefixed Requires the vendor prefix: webkit
Edge Mobile Full support YesFirefox Android Full support 32Opera Android Full support 22
Full support 22
No support 15 — 21
Prefixed
Prefixed Requires the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support Yes

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.
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.

另请参阅

文档标签和贡献者

此页面的贡献者: zsxeee
最后编辑者: zsxeee,