1

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!).

Barmar
  • 741,623
  • 53
  • 500
  • 612
Oct. Lips
  • 97
  • 1
  • 10
  • What's the problem? If you know what the actual mapping is, use that in your application. – Barmar Jun 18 '21 at 22:30
  • Although if two buttons generate the same code, something seems wrong. – Barmar Jun 18 '21 at 22:31
  • @Barmar there are two problems: 1) the buttons don't generate unique codes and 2) you can't (as far as I know) do any true custom mapping. Only rerouting button inputs after the fact, and there is only one layout for controllers ("The Standard Layout"). – Oct. Lips Jun 18 '21 at 23:18
  • Did you ever solve this? For me, in M1 MBP the xbox one controller is mapped as "standard", connected via bluetooth or USB. Did you check on https://gamepad-tester.com/? – Razvan Grigore May 19 '23 at 20:36

1 Answers1

1

The gamepad mapping is thought to solve this, but right now the only mapping is "standard". Your game should still be playable if you make the game controls customizable (for example, you could let the player choose the preferred button for the "jump" action in the game's settings dialog).

DenverCoder9
  • 2,024
  • 11
  • 32