\file SDL_joystick.h
Include file for SDL joystick event handling
The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks, with the exact joystick behind a device_index changing as joysticks are plugged and unplugged.
The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of the device (a X360 wired controller for example). This identifier is platform dependent.
Code Map
//! \file SDL_joystick.h
module lib.sdl2.joystick;
//! \name Hat positions
enum SDL_HAT_CENTERED;
enum SDL_HAT_UP;
enum SDL_HAT_RIGHT;
enum SDL_HAT_DOWN;
enum SDL_HAT_LEFT;
enum SDL_HAT_RIGHTUP;
enum SDL_HAT_RIGHTDOWN;
enum SDL_HAT_LEFTUP;
enum SDL_HAT_LEFTDOWN;
alias SDL_Joystick = _SDL_Joystick;
alias SDL_JoystickID = Sint32;
//! \file SDL_joystick.h
struct _SDL_Joystick
{
}
struct SDL_JoystickGUID
{
public:
data: Uint8[16];
}
//! Count the number of joysticks attached to the system right now
fn SDL_NumJoysticks() i32;
//! Get the implementation dependent name of a joystick. This can be called
//! before any joysticks are opened. If no name can be found, this function
//! returns NULL.
fn SDL_JoystickNameForIndex(device_index: i32) char*;
//! Open a joystick for use. The index passed as an argument refers tothe
//! N'th joystick on the system. This index is the value which will
//! identify this joystick in future joystick events.
fn SDL_JoystickOpen(device_index: i32) SDL_Joystick*;
//! Return the name for this currently opened joystick. If no name can be
//! found, this function returns NULL.
fn SDL_JoystickName(joystick: SDL_Joystick*) char*;
//! Return the GUID for the joystick at this index
fn SDL_JoystickGetDeviceGUID(device_index: i32) SDL_JoystickGUID;
//! Return the GUID for this opened joystick
fn SDL_JoystickGetGUID(joystick: SDL_Joystick*) SDL_JoystickGUID;
//! Return a string representation for this guid. pszGUID must point to at
//! least 33 bytes (32 for the string plus a NULL terminator).
fn SDL_JoystickGetGUIDString(guid: SDL_JoystickGUID, pszGUID: char*, cbGUID: i32);
//! convert a string into a joystick formatted guid
fn SDL_JoystickGetGUIDFromString(pchGUID: const(const(char)*)) SDL_JoystickGUID;
//! Returns SDL_TRUE if the joystick has been opened and currently
//! connected, or SDL_FALSE if it has not.
fn SDL_JoystickGetAttached(joystick: SDL_Joystick*) SDL_bool;
//! Get the instance ID of an opened joystick or -1 if the joystick is
//! invalid.
fn SDL_JoystickInstanceID(joystick: SDL_Joystick*) SDL_JoystickID;
//! Get the number of general axis controls on a joystick.
fn SDL_JoystickNumAxes(joystick: SDL_Joystick*) i32;
//! Get the number of trackballs on a joystick.
fn SDL_JoystickNumBalls(joystick: SDL_Joystick*) i32;
//! Get the number of POV hats on a joystick.
fn SDL_JoystickNumHats(joystick: SDL_Joystick*) i32;
//! Get the number of buttons on a joystick.
fn SDL_JoystickNumButtons(joystick: SDL_Joystick*) i32;
//! Update the current state of the open joysticks.
fn SDL_JoystickUpdate();
//! Enable/disable joystick event polling.
fn SDL_JoystickEventState(state: i32) i32;
//! Get the current state of an axis control on a joystick.
fn SDL_JoystickGetAxis(joystick: SDL_Joystick*, axis: i32) Sint16;
//! Get the current state of a POV hat on a joystick.
fn SDL_JoystickGetHat(joystick: SDL_Joystick*, hat: i32) Uint8;
//! Get the ball axis change since the last poll.
fn SDL_JoystickGetBall(joystick: SDL_Joystick*, ball: i32, dx: i32*, dy: i32*) i32;
//! Get the current state of a button on a joystick.
fn SDL_JoystickGetButton(joystick: SDL_Joystick*, button: i32) Uint8;
//! Close a joystick previously opened with SDL_JoystickOpen().
fn SDL_JoystickClose(joystick: SDL_Joystick*);
\file SDL_joystick.h
In order to use these functions, SDL_Init() must have been called with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks, and load appropriate drivers.
If you would like to receive joystick updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
Count the number of joysticks attached to the system right now
Get the implementation dependent name of a joystick. This can be called before any joysticks are opened. If no name can be found, this function returns NULL.
Open a joystick for use. The index passed as an argument refers tothe N'th joystick on the system. This index is the value which will identify this joystick in future joystick events.
\return A joystick identifier, or NULL if an error occurred.
Return the name for this currently opened joystick. If no name can be found, this function returns NULL.
Return the GUID for the joystick at this index
Return the GUID for this opened joystick
Return a string representation for this guid. pszGUID must point to at least 33 bytes (32 for the string plus a NULL terminator).
convert a string into a joystick formatted guid
Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
Get the instance ID of an opened joystick or -1 if the joystick is invalid.
Get the number of general axis controls on a joystick.
Get the number of trackballs on a joystick.
Joystick trackballs have only relative motion events associated with them and their state cannot be polled.
Get the number of POV hats on a joystick.
Get the number of buttons on a joystick.
Update the current state of the open joysticks.
This is called automatically by the event loop if any joystick events are enabled.
Enable/disable joystick event polling.
If joystick events are disabled, you must call SDL_JoystickUpdate() yourself and check the state of the joystick when you want joystick information.
The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
Get the current state of an axis control on a joystick.
The state is a value ranging from -32768 to 32767.
The axis indices start at index 0.
\name Hat positions
Get the current state of a POV hat on a joystick.
The hat indices start at index 0.
\return The return value is one of the following positions: - ::SDL_HAT_CENTERED - ::SDL_HAT_UP - ::SDL_HAT_RIGHT - ::SDL_HAT_DOWN - ::SDL_HAT_LEFT - ::SDL_HAT_RIGHTUP - ::SDL_HAT_RIGHTDOWN - ::SDL_HAT_LEFTUP - ::SDL_HAT_LEFTDOWN
Get the ball axis change since the last poll.
\return 0, or -1 if you passed it invalid parameters.
The ball indices start at index 0.
Get the current state of a button on a joystick.
The button indices start at index 0.
Close a joystick previously opened with SDL_JoystickOpen().