This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

getGamepads

Summary

Retrieves a snapshot of the data for the currently connected and interacted-with gamepads. Returns a Gamepad object.

Method of dom/Navigatordom/Navigator

Syntax

var result = navigator.getGamepads();

Return Value

Returns an object of type

gamePads collection.

Examples

This example detects when a gamepad is connected to the computer.

window.addEventListener("gamepadconnected", function(e) {
  var gp = navigator.getGamepads()[0];
  console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
  gp.index, gp.id,
  gp.buttons.length, gp.axes.length);
});

Related specifications

W3C Gamepad Specification
W3C Working Draft

Attributions