GamepadEvent
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.
GamepadEvent
интерфейс Gamepad API
содержит ссылки на геймпады, подключённые к системе, передающиеся при возникновении событий Window.gamepadconnected и gamepaddisconnected
.
Свойства
GamepadEvent.gamepad
Только для чтения-
Возвращает объект
Gamepad
, предоставляющий доступ к данным геймпада, для возникнувшего события.
Примеры
Свойства геймпада передаются при возникновении события Window.gamepadconnected.
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,
);
});
И события gamepaddisconnected
.
window.addEventListener("gamepaddisconnected", function (e) {
console.log(
"Gamepad disconnected from index %d: %s",
e.gamepad.index,
e.gamepad.id,
);
});
Спецификации
Specification |
---|
Gamepad # gamepadevent-interface |
Совместимость с браузерами
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
GamepadEvent | ||||||||||||
GamepadEvent() constructor | ||||||||||||
gamepad | ||||||||||||
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.