Created
May 9, 2018 20:04
-
-
Save jpenney1/b3bd9c3a3866e998d4dda3610604297b to your computer and use it in GitHub Desktop.
with this snippet, you can add an event listener to any webpage which will log the button pressed to the console, along with its entire availbale buttons array and index at which it was found. Anyone know how if there's a naive way to determine which button in the array is which?
This file contains hidden or 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 gameLoop = function(res) { | |
var gamepad = navigator.getGamepads(); | |
navigator.getGamepads()[0].buttons.forEach(function(button, i, buttons) { | |
if(button.pressed) console.log('pressed: ', buttons.slice(),' i: ', i, buttons[i]) | |
}); | |
requestAnimationFrame(gameLoop) | |
} | |
window.addEventListener('gamepadconnected', gameLoop) | |
// src: https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment