Skip to content

Instantly share code, notes, and snippets.

@victorbstan
Last active December 24, 2015 18:59
Show Gist options
  • Save victorbstan/6846918 to your computer and use it in GitHub Desktop.
Save victorbstan/6846918 to your computer and use it in GitHub Desktop.
Detecting gamepads in Chrome Canary
<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