How can I determine "A" and "B" button locations?

I am using MonoGame 3.8.1 to read input from a variety of controllers for my game. I am using GamePad.InitDatabase(); to get information about the gamepad and all of my controllers work fairly well.

Switch Pro and Xbox controllers both have A,B,X,Y buttons.

On the Xbox, the bottom button in the arrangement of the buttons is the A button:

  Y
X   B
  A <--Bottom Button

On the Switch, the bottom in the arrangement of buttons is the B button:

  X
Y   A
  B <--Buttom Button

The problem I am running into is that I want the bottom button to be my jump. These controllers report their DisplayName which gives some hints about the controller type (such as “Nintendo Switch Pro Controller”), but I only have a few controllers to test with, so I’m afraid there may be controllers with DisplayNames that I don’t know about.

Is there a different way to determine the controller type besides the DisplayName which can help me decide whether to swap A and B for jump? Or do I need to go through the entire SDL controller database and take a best-guess about which to swap?

Of course, I plan on providing a screen for the user to change the defaults, but my hope was to have a good set of defaults.

Hey, in my case I’ve added a layer on top where I ask for the current button and if the game is running on Switch and result is Button.A the method returns Button.B and viceversa.

Thanks for the feedback, but in my case my game is PC only. On the PC, both Xbox and Switch controllers can be plugged in, so I can’t rely on the platform to tell me whether to swap.

how about allowing the player to switch different controller layouts?
I remember some old school games allowed different configurations depending on the user preference.
And I always picked up the one where the button below was jump

how about allowing the player to switch different controller layouts?

If it’s only that 1 button, it could be feasible to like have a starting screen just saying “press the jump button” so the player does initially just decide by himself the first time he starts the game

There is GamePad.GetCapabilities(). And it has some interesting fields like DisplayName. You could query that and detect Nintendo’s gamepads.

Also I REALLY recommend making a flip switch in your game’s settings. I am very used to nintendo controllers, but I play on an xbox controler on pc, and flipped buttons are very confusing, I always want them to be flipped back.

You have to use GamePad.GetCapabilities() as @Martenfur says. At least, that is the most straightforward way.

There is another way that involves changing the values in the SDL database that MonoGame uses but it’s complicated and I wouldn’t recommend it. I had to do that when porting my game to the new AtariVCS as their controllers have some really finicky things going on.