Wiki Page Content

Differences between revisions 12 and 13
Revision 12 as of 2013-09-28 08:14:05
Size: 1949
Comment: Corrected: device_index NOT used by future events, added reference to SDL_JoystickInstanceID which is.
Revision 13 as of 2014-10-10 19:58:10
Size: 1947
Comment: Removed *s and added ().
Deletions are marked like this. Additions are marked like this.
Line 51: Line 51:
* The device_index passed as an 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 device_index passed as an 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.
Line 53: Line 53:
* The joystick subsystem must be initialized before a joystick can be opened for use. The joystick subsystem must be initialized before a joystick can be opened for use.

DRAFT

SDL_JoystickOpen

Use this function to open a joystick for use.

Syntax

SDL_Joystick* SDL_JoystickOpen(int device_index)

Function Parameters

device_index

the index of the joystick to query

Return Value

Returns a joystick identifier or NULL if an error occurred; call SDL_GetError() for more information.

Code Examples

SDL_Joystick *joy;

// Initialize the joystick subsystem
SDL_InitSubSystem(SDL_INIT_JOYSTICK);

// Check for joystick
if (SDL_NumJoysticks() > 0) {
    // Open joystick
    joy = SDL_JoystickOpen(0);

    if (joy) {
        printf("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));
    } else {
        printf("Couldn't open Joystick 0\n");
    }

    // Close if opened
    if (SDL_JoystickGetAttached(joy)) {
        SDL_JoystickClose(joy);
    }
}

Remarks

The device_index passed as an 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.

There are a number of functions that list this one as a RF based on the old wiki. Do we want them all to be reciprocated here?


CategoryAPI, CategoryJoystick

None: SDL_JoystickOpen (last edited 2015-05-31 18:48:51 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit