Wiki Page Content

Differences between revisions 8 and 9
Revision 8 as of 2016-04-10 22:30:07
Size: 1680
Comment: Replaced printf() with SDL_Log() in example.
Revision 9 as of 2016-04-10 22:32:56
Size: 1760
Comment: Fixed memory leak in still incomplete example (Feedback 2016-03-27).
Deletions are marked like this. Additions are marked like this.
Line 41: Line 41:
        char *mapping;
Line 43: Line 44:
        SDL_Log("Controller %i is mapped as \"%s\".", i, SDL_GameControllerMapping(ctrl));         mapping = SDL_GameControllerMapping(ctrl);
SDL_Log("Controller %i is mapped as \"%s\".", i, mapping);



Use this function to get the current mapping of a Game Controller.


char* SDL_GameControllerMapping(SDL_GameController* gamecontroller)

Function Parameters


the game controller you want to get the current mapping for

Return Value

Returns a string that has the controller's mapping. More information about the mapping can be found on SDL_GameControllerAddMapping; call SDL_GetError() for more information.

Code Examples

#include "SDL.h"

/* ... */

SDL_GameController *ctrl;
int i;


for (i = 0; i < SDL_NumJoysticks(); ++i) {
    if (SDL_IsGameController(i)) {
        char *mapping;
        SDL_Log("Index \'%i\' is a compatible controller, named \'%s\'", i, SDL_GameControllerNameForIndex(i));
        ctrl = SDL_GameControllerOpen(i);
        mapping = SDL_GameControllerMapping(ctrl);
        SDL_Log("Controller %i is mapped as \"%s\".", i, mapping);
    } else {
        SDL_Log("Index \'%i\' is not a compatible controller.", i);


The returned string must be freed with SDL_free().

CategoryAPI, CategoryGameController

None: SDL_GameControllerMapping (last edited 2016-04-10 22:39:25 by PhilippWiesemann)

Please include your contact information if you'd like to receive a reply.