THIS PAGE IS A WORK IN PROGRESS ... Please make edits to this page to improve it!
Get the Joystick ID from a Game Controller.
SDL_Joystick* SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
gamecontroller |
the game controller object that you want to get a joystick from |
Returns a SDL_Joystick object; call SDL_GetError() for more information.
This function will give you a SDL_Joystick object, which allows you to use the SDL_Joystick functions with a SDL_GameController object. This would be useful for getting a joystick's position at any given time, even if it hasn't moved (moving it would produce an event, which would have the axis' value).
The pointer returned is owned by the SDL_GameController. You should not call SDL_JoystickClose() on it, for example, since doing so will likely cause SDL to crash.
This function is available since SDL 2.0.0.
#include <stdio.h> /* for printf() */
/* ... */
SDL_GameController *ctrl;
SDL_Joystick *joy;int i;
for(i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
"Index \'%i\' is a compatible controller, named \'%s\'\n", i, SDL_GameControllerNameForIndex(i));
printf(
ctrl = SDL_GameControllerOpen(i);
joy = SDL_GameControllerGetJoystick(ctrl);else {
} "Index \'%i\' is not a compatible controller.\n", i);
printf(
} }
CategoryAPI, CategoryGameController, CategoryDraft