SDL_AddGamepadMapping(3)
π SDL_AddGamepadMapping(3) β SDL3 FUNCTIONS π
okay bestie, listen. we're in the SDL3 house tonight and today's main character is SDL_AddGamepadMapping β she lives in the SDL3 FUNCTIONS section and she is so much cooler than her name makes her sound. let's go π«Ά
β¨ NAME β¨
SDL_AddGamepadMapping β add support for gamepads that SDL is unaware of, or change the binding of an existing gamepad.
like. she's the girl who introduces your random third-party controller to the group chat. and she can also rearrange the buttons on a gamepad SDL already knows. iconic behaviour honestly π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_gamepad.h>
int SDL_AddGamepadMapping(const char *mapping);
β¨ DESCRIPTION β¨
so the mapping string is formatted like this:
"GUID,name,mapping"
break it down, bestie:
GUIDβ this is the string value you get fromSDL_GUIDToString()nameβ the human readable string for the devicemappingβ the actual gamepad mappings, mapping gamepad things onto joystick things
and under Windows there's a reserved GUID of "xinput" that covers all XInput devices. reserved. exclusive. she doesn't share. π
the mapping format for joystick goes like this:
bXβ a joystick button, index XhX.Yβ hat X with value YaXβ axis X of the joystick
and the little plot twist: buttons can be used as gamepad axes and vice versa. no cap, they're interchangeable like that π₯
if a device with this GUID is already plugged in, SDL will generate an SDL_EVENT_GAMEPAD_ADDED event. she just shows up and announces herself.
here's an example of a valid mapping for a gamepad, and yes it's long, it's giving β¨ full makeup routine β¨:
"341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7"
β¨ FUNCTION PARAMETERS β¨
mappingβ the mapping string. that's it, that's the whole job π
β¨ RETURN VALUE β¨
- returns
1if a new mapping is added π - returns
0if an existing mapping is updated π¦ - returns
-1on failure π
and if you got that -1, call SDL_GetError() for more information. she'll tell you what went wrong, fr fr.
β¨ THREAD SAFETY β¨
it is safe to call this function from any thread. multitasking queen, she contains multitudes πΈ
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0. she's not new new, but she's not ancient either. a modern classic π
β¨ SEE ALSO β¨
SDL_AddGamepadMappingsFromFile(3)SDL_AddGamepadMappingsFromIO(3)SDL_GetGamepadMapping(3)SDL_GetGamepadMappingForGUID(3)SDL_HINT_GAMECONTROLLERCONFIG(3)SDL_HINT_GAMECONTROLLERCONFIG_FILE(3)SDL_EVENT_GAMEPAD_ADDED(3)
okay that's the whole page, bestie, you ate that π go forth and map your weird off-brand controller with confidence π
Simple Directmedia Layer β’ SDL 3.4.18 β’ SDL_AddGamepadMapping(3) β mwah, take care of her, she's doing her best π§π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms