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
Mozilla Developer Network : [navigator.getGamepads method Article]
Microsoft Developer Network: [Gamepad API in DevChannel Article]