Skip to content

Instantly share code, notes, and snippets.

@luser
Created December 6, 2013 20:45
Show Gist options
  • Save luser/7831796 to your computer and use it in GitHub Desktop.
Save luser/7831796 to your computer and use it in GitHub Desktop.
Gamepad API button handling
function listButtons(gamepad) {
for (var i = 0; i < gamepad.buttons.length; i++) {
var b = gamepad.buttons[i];
var pressed, val;
if (typeof(b) == "object") {
pressed = b.pressed;
val = b.value;
} else {
val = b;
pressed = b == 1.0;
}
console.log("Button %d: %s (%f)", i, pressed ? "pressed" : "not pressed", val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment