Gamepad: index プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

Gamepad.indexGamepad インターフェイスのプロパティで、現在システムに接続されているそれぞれの機器の整数の固有番号(自動採番)の整数を返します。

これは複数のコントローラーを識別するために使用することができます。接続が解除された後で再接続されたゲームパッドは、同じ番号を保持します。

数値です。

js
window.addEventListener("gamepadconnected", () => {
  const gp = navigator.getGamepads()[0];
  gamepadInfo.textContent = `Gamepad connected at index ${gp.index}: ${gp.id}.`;
});

仕様書

Specification
Gamepad
# dom-gamepad-index

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
index

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報