I'm currently building a little game in vanilla JS, but as I was working on controller (specs at bottom) input it mismapped the buttons. It has the same number of inputs as the gamepad API standard controller, and all the same controls, but it doesn't match in an unplayable way. I used another program (available in the API docs) to test my controls, and when I found out that wasn't working, I wrote this little ditty:
let gamepad = null;
window.addEventListener("gamepadconnected", function(e) {
console.log(`gamepad: connected`);
gamepad = e.gamepad;
});
function loop(){
if(gamepad){
let buttons = gamepad.buttons;
for(let n = 0; n <= 16; n++){
//16 is the maximum buttons allowed, I checked
if(buttons[n].pressed)
console.log(`Pressed: ${n}`);
}
}
}
setInterval(loop,45);
For a list of mismatched controls, see the table below:
Index | What should be | what is |
---|---|---|
0 | A | Power |
1 | B | A |
2 | X | B |
3 | Y | X |
4 | left bumper | n/a |
5 | right bumper | Y, left bumper |
6 | left trigger | n/a |
7 | right trigger | n/a |
8 | select | select, right bumper |
9 | start | n/a |
10 | left stick button | n/a |
11 | right stick button | left stick button |
12 | dpad_up | dpad_up |
13 | dpad_down | dpad_down |
14 | dpad_left | dpad_left |
15 | dpad_right | dpad_right |
16 | power | right stick button, start |
if anyone has any type of workaround, I would greatly appreciate it.
Notes: I'm using an M1 macbook pro (recent model), Xbox One controller w/bluetooth and headphone jack, and Replit as an IDE on Firefox. I'm happy to use JQuery, but unless it is absolutely necessary I would like to use no other outside libraries (feel free to suggest them though!).