Created
December 6, 2013 19:17
-
-
Save luser/7830549 to your computer and use it in GitHub Desktop.
Gamepad API using navigator.getGamepads()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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