Gamepad.id

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。

The Gamepad.id property of the Gamepad interface returns a string containing some information about the controller.

The exact syntax is not strictly specified, but in Firefox it will contain three pieces of information separated by dashes (-):

  • Two 4-digit hexadecimal strings containing the USB vendor and product id of the controller
  • The name of the controller as provided by the driver.

For example, a PS2 controller returned 810-3-USB Gamepad.

This information is intended to allow you to find a mapping for the controls on the device as well as display useful feedback to the user.

Syntax

readonly    attribute DOMString           id;

Example

window.addEventListener("gamepadconnected", function() {
  var gp = navigator.getGamepads()[0];
  gamepadInfo.innerHTML = "Gamepad connected at index " + gp.index + ": " + gp.id + ".";
});

Value

A string.

Specifications

Specification Status Comment
Gamepad
The definition of 'Gamepad.id' in that specification.
Working Draft Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support

35

21 — 34 webkit

(Yes)

29

24 — 281

No

22

15 — 21 webkit

No
FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support No (Yes) (Yes)32 No No No

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

See also

Using the Gamepad API

文档标签和贡献者