Window: gamepadconnected イベント
gamepadconnected
イベントは、ゲームパッドが接続されたことをブラウザーが検出したとき、またはゲームパッドのボタン/軸が初めて使用されたときに発生します。
このイベントは、文書の gamepad
権限ポリシーが不許可になっている場合には発生しません。
このイベントはキャンセル不可で、バブリングしません。
例
ゲームパッドが接続されたことを通知するには、addEventListener()
を使用してウィンドウにハンドラーを追加します。
js
window.addEventListener("gamepadconnected", (event) => {
// すべてのボタンと軸の値は、次の方法でアクセスできます。
const gamepad = event.gamepad;
});
また、window.ongamepadconnected
イベントハンドラープロパティを使用して、gamepadconnected
イベントのハンドラーを確立することもできます。
js
window.ongamepadconnected = (event) => {
// すべてのボタンと軸の値は、次の方法でアクセスできます。
const gamepad = event.gamepad;
};
仕様書
Specification |
---|
Gamepad # event-gamepadconnected |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
gamepadconnected event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- 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.