SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)

Draft

THIS PAGE IS A WORK IN PROGRESS ... Please make edits to this page to improve it!

SDL_GameControllerGetStringForAxis

Convert from an SDL_GameControllerAxis enum to a string.

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 3.0.0.

Code Examples


#include "SDL.h"

int main(int argc, char* argv[])
{
    SDL_Event event;
    SDL_bool running = SDL_TRUE;

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

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

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

    SDL_Quit();

    return 0;
}
SDL_GameControllerGetAxisFromString

CategoryAPI, CategoryGameController, CategoryDraft


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.