--- title: GamepadEvent slug: Web/API/GamepadEvent translation_of: Web/API/GamepadEvent ---
{{APIRef("Gamepad API")}}
The GamepadEvent interface of the Gamepad API contains references to gamepads connected to the system, which is what the gamepad events {{domxref("Window.gamepadconnected")}} and {{domxref("Window.gamepaddisconnected")}} are fired in response to.
GamepadEvent
object.The gamepad property being called on a fired {{domxref("Window.gamepadconnected")}} event.
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); });
And on a {{domxref("Window.gamepaddisconnected")}} event.
window.addEventListener("gamepaddisconnected", function(e) { console.log("Gamepad disconnected from index %d: %s", e.gamepad.index, e.gamepad.id); });
Specification | Status | Comment |
---|---|---|
{{SpecName("Gamepad", "#gamepadevent-interface", "GamepadEvent")}} | {{Spec2("Gamepad")}} | Initial definition |
{{Compat("api.GamepadEvent")}}