Convert from an SDL_GameControllerAxis enum to a string.
Defined in SDL_gamecontroller.h
axis | an enum value for a given SDL_GameControllerAxis |
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.
The caller should not SDL_free() the returned string.
This function is available since SDL 2.0.0.
#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;
}