1)It might be a typo but the code you provided seems to be missing a closing curly brace.
2) Your code assumes the use of the 'webkitGetGamepads()' method, which is specific to webKit-based browsers. You can use the standard 'navigator.getGamepads()' method instead to give you more access to compatibility. Description and sample code is found at -
Navigator: getGamepads() method[
^]
3) As per OriginalGriff, you need to first check if the browser supports the 'getGamepads' method. If it does, retrieve the list of connected gamepads using 'navigator.getGamepads()'. Start by accessing the first gamepad in the list.
4) Now check if a button is pressed -
function gameLoop() {
if (navigator.getGamepads) {
var gamepads = navigator.getGamepads();
var wgp = gamepads[0];
if (wgp.buttons[12].pressed || wgp.buttons[4].pressed) {
console.log('move');
}
}
}
gameLoop();