Navigator: getGamepads() メソッド
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.
* Some parts of this feature may have varying levels of support.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
Navigator.getGamepads()
メソッドは Gamepad
の配列を返します。それぞれがこの端末に接続されているゲームパッドを表します。
セッション中にゲームパッドが切断された場合、配列の要素は null
になる可能性がありますので、残りのゲームパッドは同じインデックスを保持します。
構文
js
getGamepads()
引数
なし。
返値
例外
SecurityError
DOMException
-
権限ポリシーによって、この機能の使用がブロックされた場合。
例
js
window.addEventListener("gamepadconnected", (e) => {
const gp = navigator.getGamepads()[e.gamepad.index];
console.log(
`Gamepad connected at index ${gp.index}: ${gp.id} with ${gp.buttons.length} buttons, ${gp.axes.length} axes.`,
);
});
仕様書
Specification |
---|
Gamepad # dom-navigator-getgamepads |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getGamepads | ||||||||||||||
Secure context required |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.