Gamepad
接口在
手柄 API
defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id.
A Gamepad object can be returned in one of two ways: via the
gamepad
特性为
gamepadconnected
and
gamepaddisconnected
events, or by grabbing any position in the array returned by the
Navigator.getGamepads()
方法。
Gamepad.axes
只读
An array representing the controls with axes present on the device (e.g. analog thumb sticks).
Gamepad.buttons
只读
gamepadButton
objects representing the buttons present on the device.
Gamepad.connected
只读
A boolean indicating whether the gamepad is still connected to the system.
Gamepad.displayId
只读
VRDisplay.displayId
of an associated
VRDisplay
(if relevant) — the
VRDisplay
that the gamepad is controlling the displayed scene of.
Gamepad.id
只读
DOMString
containing identifying information about the controller.
Gamepad.index
只读
An integer that is auto-incremented to be unique for each device currently connected to the system.
Gamepad.mapping
只读
A string indicating whether the browser has remapped the controls on the device to a known layout.
Gamepad.timestamp
只读
DOMHighResTimeStamp
representing the last time the data for this gamepad was updated.
The following interfaces are defined in the Gamepad Extensions specification, and provide access to experimental features like haptic feedback and WebVR controller pose information.
Gamepad.hand
只读
An enum defining what hand the controller is being held in, or is most likely to be held in.
Gamepad.hapticActuators
只读
GamepadHapticActuator
objects, each of which represents haptic feedback hardware available on the controller.
Gamepad.pose
只读
GamepadPose
object representing the pose information associated with a WebVR controller (e.g. its position and orientation in 3D space).
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);
});
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gamepad
|
Chrome
35
|
Edge ≤18 |
Firefox
29
|
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
|
Gamepad()
构造函数
|
Chrome 35 | Edge 12 |
Firefox
29
|
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
|
Edge 12 |
Firefox
29
|
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
|
buttons
|
Chrome
35
|
Edge 12 |
Firefox
29
|
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
|
connected
|
Chrome
35
|
Edge 12 |
Firefox
29
|
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
|
displayId
弃用
|
Chrome
? — 80
Disabled
|
Edge 15 |
Firefox
55
|
IE No | Opera ? | Safari No | WebView Android No |
Chrome Android
? — 80
|
Firefox Android 55 | Opera Android ? | Safari iOS No |
Samsung Internet Android
Yes
|
hand
|
Chrome No | Edge 15 — 79 |
Firefox
Yes
Disabled
|
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
|
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
|
Edge 12 |
Firefox
29
|
IE No |
Opera
22
|
Safari No | WebView Android No |
Chrome Android
35
|
Firefox Android 32 |
Opera Android
22
|
Safari iOS No |
Samsung Internet Android
4.0
|
index
|
Chrome
35
|
Edge 12 |
Firefox
29
|
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
|
映射
|
Chrome
35
|
Edge 12 |
Firefox
29
|
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
|
pose
|
Chrome No | Edge 15 — 79 |
Firefox
Yes
Disabled
|
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
|
Edge 12 |
Firefox
29
|
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
|
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 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。