Skip to content

Instantly share code, notes, and snippets.

@luser
Created December 6, 2013 19:17
Show Gist options
  • Save luser/7830549 to your computer and use it in GitHub Desktop.
Save luser/7830549 to your computer and use it in GitHub Desktop.
Gamepad API using navigator.getGamepads()
var gamepad_count = 0;
function pollGamepads() {
var gamepads = navigator.getGamepads();
if (gamepads.length != gamepad_count) {
gamepad_count = gamepads.length;
for (var i = 0; i < gamepads.length; i++) {
console.log("Gamepad %d: %s. %d buttons, %d axes",
i, gamepads[i].id,
gamepads[i].buttons.length, gamepads[i].axes.length);
}
}
}
setInterval(pollGamepads, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment