docs.rodeo

MDN Web Docs mirror

Gamepad

{{APIRef("Gamepad API")}} {{SecureContext_Header}} 

The Gamepad interface of the Gamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id.

A Gamepad object can be returned in one of two ways: via the gamepad property of the {{domxref("Window.gamepadconnected_event", "gamepadconnected")}}  and {{domxref("Window.gamepaddisconnected_event", "gamepaddisconnected")}}  events, or by grabbing any position in the array returned by the {{domxref("Navigator.getGamepads()")}}  method.

[!NOTE] The support of gamepad features varies across different combinations of platforms and controllers. Even if the controller supports a certain feature (for example, haptic feedback), the platform may not support it for that controller.

Instance properties

Example

window.addEventListener("gamepadconnected", (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,
  );
});

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN