(This is the legacy documentation for stable SDL2, the current stable version; SDL3 is the current development version.)

SDL_GameControllerGetStringForAxis

Convert from an SDL_GameControllerAxis enum to a string.

Header File

Defined in SDL_gamecontroller.h

Syntax

const char* SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);

Function Parameters

axis an enum value for a given SDL_GameControllerAxis

Return Value

Returns a string for the given axis, or NULL if an invalid axis is specified. The string returned is of the format used by SDL_GameController mapping strings.

Remarks

The caller should not SDL_free() the returned string.

Version

This function is available since SDL 2.0.0.

Code Examples

#include "SDL.h"

int main(int argc, char **argv)
{
    SDL_Event event;
    int running = 1;

    if (SDL_Init(SDL_INIT_GAMECONTROLLER) < 0) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error while initializing SDL2 library : %s", SDL_GetError());
        return EXIT_FAILURE;
    }

    while (running) {
        while (SDL_PollEvent(&event) > 0) {
            if (event.type == SDL_QUIT) {
                running = 0;
            }

            if (event.type == SDL_CONTROLLERAXISMOTION) {
                char const *axisName = SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis) event.caxis.axis);
                const int axisValue = event.caxis.value;
                SDL_Log("Axis used : %s\tAxis value : %d", axisName, axisValue);
            }
        }
    }

    SDL_Quit();

    return EXIT_SUCCESS;
}

See Also


CategoryAPI, CategoryAPIFunction, CategoryGameController