The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Button name and colour library/database
congusbongus


Joined: 06 Nov 2015
Posts: 2
I've recently created a small C library intended to work with the game controller API, which gives you button/axis names and colours. So if you want to tell your player in-game to "press the A button", but the player has a PS4 controller, the library can tell you that "their A button is actually teal and named X".

https://github.com/cxong/SDL_JoystickButtonNames

Here's a minimal code sample:

Code:
SDL_Joystick *joy;
char name[256];
Uint8 r, g, b;
SDLJBN_GetButtonNameAndColor(joy, SDL_CONTROLLER_BUTTON_A, name, &r, &g, &b);
printf("Button A is %s with color rgb(%d,%d,%d)\n", name, r, g, b);


Which, if your controller is a Logitech Dual Action, will print this:

Code:
Button A is 2 with color rgb(244,244,244)


Check out the project page for more details; there's a sample program you can build with CMake to detect all the buttons/axes on your controllers.

This project needs your help! So far I only have 2 controllers in the database because that's all I have access to. If you have controllers, please try the examples out and see if the button names and colours match, and if not let me know so I can add them to the database.

Also, let me know if this is useful or how it can be improved. I know that ideally you would display an image or sprite representing the button but that seems too high level for an SDL library, so this was the next best thing.

I'm new to these forums but I've found that this idea has been talked about in the past, here:
https://forums.libsdl.org/viewtopic.php?t=10174
https://forums.libsdl.org/viewtopic.php?t=10594
I'm not sure if anything happened with those.