THIS PAGE IS A WORK IN PROGRESS ... Please make edits to this page to improve it!
Open a joystick for use.
int device_index); SDL_Joystick* SDL_JoystickOpen(
device_index |
the index of the joystick to query |
Returns a joystick identifier or NULL if an error occurred; call SDL_GetError() for more information.
The device_index
argument refers to the N'th joystick presently recognized by SDL on the system. It is NOT the same as the instance ID used to identify the joystick in future events. See SDL_JoystickInstanceID() for more details about instance IDs.
The joystick subsystem must be initialized before a joystick can be opened for use.
This function is available since SDL 2.0.0.
SDL_Joystick *joy;
// Initialize the joystick subsystem
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
// Check for joystick
if (SDL_NumJoysticks() > 0) {
// Open joystick
0);
joy = SDL_JoystickOpen(
if (joy) {
"Opened Joystick 0\n");
printf("Name: %s\n", SDL_JoystickNameForIndex(0));
printf("Number of Axes: %d\n", SDL_JoystickNumAxes(joy));
printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joy));
printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joy));
printf(else {
} "Couldn't open Joystick 0\n");
printf(
}
// Close if opened
if (SDL_JoystickGetAttached(joy)) {
SDL_JoystickClose(joy);
} }
CategoryAPI, CategoryJoystick, CategoryDraft