Last active
December 24, 2015 18:59
-
-
Save victorbstan/6846918 to your computer and use it in GitHub Desktop.
Detecting gamepads in Chrome Canary
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
<html> | |
<head> | |
<title>Get Gamepads</title> | |
</head> | |
<body> | |
<!-- adapted from http://stackoverflow.com/questions/10839310/html5-gamepad-api-on-chrome --> | |
<script> | |
function updateStatus() { | |
window.webkitRequestAnimationFrame(updateStatus); | |
var gamepads = navigator.webkitGetGamepads(); | |
var data = ''; | |
for (var padindex = 0; padindex < gamepads.length; ++padindex) { | |
var pad = gamepads[padindex]; | |
if (!pad) continue; | |
data += '<pre>' + pad.index + ": " + pad.id + "<br/>"; | |
for (var i = 0; i < pad.buttons.length; ++i) | |
data += "button" + i + ": " + pad.buttons[i] + "<br/>"; | |
for (var i = 0; i < pad.axes.length; ++i) | |
data += "axis" + i + ": " + pad.axes[i] + "<br/>"; | |
} | |
document.body.innerHTML = data; | |
} | |
window.webkitRequestAnimationFrame(updateStatus); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment