Differentiate between different Gamepad Devices?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tyo

I’m wondering if it is at all possible for the engine to tell the difference between different kinds of controllers the user is using and change some UI information based on the kind of game pad plugged in. For example, if an Xbox controller is in, I’d want the game to display “Press A to Jump” and if a PS4 controller is in, I’d want the game to display “Press X to Jump.”

I realize I could just make this a setting for the player to change however they please, but I’m wondering if I could in some way automate this. I’ve already figured out how to get the game to tell the difference between a mouse/keyboard command and a gamepad command on the fly, so I’m hopeful that something like this is possible too.

Thanks!

:bust_in_silhouette: Reply From: Dlean Jeans

Godot has a function called Input.get_joy_name(). I got no gamepads to test but I guess it would return whether it’s a PS4 or an Xbox controller.

If that’s true then use it together with the signal Input.joy_connection_changed as described in this answer would do.

I’d also say that get_joy_name() is the way to go.
Here’s a list of controller names (& data) in case tyo needs some data to test the name checks:
http://hg.libsdl.org/SDL/file/tip/src/joystick/SDL_gamecontrollerdb.h

( I’d only check for parts of the string, maybe using a RegExp )

wombatstampede | 2019-06-12 07:56

In case you are reading this in 2022, the SDL source code is no longer at the link listed in the above comment. The SDL library is now hosted at Github: GitHub - libsdl-org/SDL: Simple Directmedia Layer. The SDL_gamecontrollerdb.h file can now be found here: https://github.com/libsdl-org/SDL/blob/main/src/joystick/SDL_gamecontrollerdb.h

Donatello | 2022-08-13 15:16

Wow, they do a lot of refactoring. It’s only Jan 2023. Now it’s here: https://github.com/libsdl-org/SDL/blob/main/src/joystick/SDL_gamepad_db.h

Razzlegames | 2023-01-30 04:47