SDL 2.0
|
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_rwops.h"
#include "SDL_sensor.h"
#include "SDL_joystick.h"
#include "begin_code.h"
#include "close_code.h"
Go to the source code of this file.
Data Structures | |
struct | SDL_GameControllerButtonBind |
Macros | |
#define | SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1) |
Typedefs | |
typedef struct _SDL_GameController | SDL_GameController |
Include file for SDL game controller event handling
In order to use these functions, SDL_Init() must have been called with the SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system for game controllers, and load appropriate drivers.
If you would like to receive controller updates while the application is in the background, you should set the following hint before calling SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
Definition in file SDL_gamecontroller.h.
#define SDL_GameControllerAddMappingsFromFile | ( | file | ) | SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1) |
Load a set of mappings from a file, filtered by the current SDL_GetPlatform()
Convenience macro.
Definition at line 181 of file SDL_gamecontroller.h.
typedef struct _SDL_GameController SDL_GameController |
Definition at line 61 of file SDL_gamecontroller.h.
The list of axes available from a controller
Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though advanced UI will allow users to set or autodetect the dead zone, which varies between controllers.
Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully pressed) when reported by SDL_GameControllerGetAxis(). Note that this is not the same range that will be reported by the lower-level SDL_GetJoystickAxis().
Definition at line 635 of file SDL_gamecontroller.h.
Enumerator | |
---|---|
SDL_CONTROLLER_BINDTYPE_NONE | |
SDL_CONTROLLER_BINDTYPE_BUTTON | |
SDL_CONTROLLER_BINDTYPE_AXIS | |
SDL_CONTROLLER_BINDTYPE_HAT |
Definition at line 82 of file SDL_gamecontroller.h.
The list of buttons available from a controller
Definition at line 744 of file SDL_gamecontroller.h.
Definition at line 63 of file SDL_gamecontroller.h.
|
extern |
Add support for controllers that SDL is unaware of or to cause an existing controller to have a different binding.
The mapping string has the format "GUID,name,mapping", where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. Under Windows there is a reserved GUID of "xinput" that covers all XInput devices. The mapping format for joystick is: {| |bX |a joystick button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick |} Buttons can be used as a controller axes and vice versa.
This string shows an example of a valid mapping for a controller:
If this function is called before SDL_Init, SDL will generate an SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged in at the time that SDL_Init is called.
mappingString | the mapping string. |
|
extern |
To count the number of game controllers in the system for the following:
Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is: guid,name,mappings
Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones. Under Windows there is a reserved GUID of "xinput" that covers any XInput devices. The mapping format for joystick is: bX - a joystick button, index X hX.Y - hat X with value Y aX - axis X of the joystick Buttons can be used as a controller axis and vice versa.
This string shows an example of a valid mapping for a controller
Load a set of Game Controller mappings from a seekable SDL data stream.
You can call this function several times, if needed, to load different database files.
If a new mapping is loaded for an already known controller GUID, the later version will overwrite the one currently loaded.
If this function is called before SDL_Init, SDL will generate an SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged in at the time that SDL_Init is called.
Mappings not belonging to the current platform or with no platform field specified will be ignored (i.e. mappings for Linux will be ignored in Windows, etc).
This function will load the text database entirely in memory before processing it, so take this into consideration if you are in a memory constrained environment.
rw | the data stream for the mappings to be added. |
freerw | non-zero to close the stream after being read. |
|
extern |
Close a game controller previously opened with SDL_GameControllerOpen().
gamecontroller | a game controller identifier previously returned by SDL_GameControllerOpen(). |
|
extern |
Query or change current state of Game Controller events.
If controller events are disabled, you must call SDL_GameControllerUpdate() yourself and check the state of the controller when you want controller information.
Any number can be passed to SDL_GameControllerEventState(), but only -1, 0, and 1 will have any effect. Other numbers will just be returned.
state | can be one of SDL_QUERY , SDL_IGNORE , or SDL_ENABLE . |
|
extern |
Get the SDL_GameController associated with an instance id.
joyid | the instance id to get the SDL_GameController for. |
|
extern |
Get the SDL_GameController associated with a player index.
Please note that the player index is not the device index, nor is it the instance id!
player_index | the player index, which is not the device index or the instance id! |
|
extern |
Return the sfSymbolsName for a given axis on a game controller on Apple platforms.
gamecontroller | the controller to query. |
axis | an axis on the game controller. |
|
extern |
Return the sfSymbolsName for a given button on a game controller on Apple platforms.
gamecontroller | the controller to query. |
button | a button on the game controller. |
|
extern |
Check if a controller has been opened and is currently connected.
gamecontroller | a game controller identifier previously returned by SDL_GameControllerOpen(). |
|
extern |
Get the current state of an axis control on a game controller.
The axis indices start at index 0.
For thumbsticks, the state is a value ranging from -32768 (up/left) to 32767 (down/right).
Triggers range from 0 when released to 32767 when fully pressed, and never return a negative value. Note that this differs from the value reported by the lower-level SDL_JoystickGetAxis(), which normally uses the full range.
gamecontroller | a game controller. |
axis | an axis index (one of the SDL_GameControllerAxis values). |
|
extern |
Convert a string into SDL_GameControllerAxis enum.
This function is called internally to translate SDL_GameController mapping strings for the underlying joystick device into the consistent SDL_GameController mapping. You do not normally need to call this function unless you are parsing SDL_GameController mappings in your own code.
Note specially that "righttrigger" and "lefttrigger" map to SDL_CONTROLLER_AXIS_TRIGGERRIGHT
and SDL_CONTROLLER_AXIS_TRIGGERLEFT
, respectively.
str | string representing a SDL_GameController axis. |
SDL_CONTROLLER_AXIS_INVALID
if no match was found.
|
extern |
Get the SDL joystick layer binding for a controller axis mapping.
gamecontroller | a game controller. |
axis | an axis enum value (one of the SDL_GameControllerAxis values). |
.bindType
will be SDL_CONTROLLER_BINDTYPE_NONE
.
|
extern |
Get the SDL joystick layer binding for a controller button mapping.
gamecontroller | a game controller. |
button | an button enum value (an SDL_GameControllerButton value). |
.bindType
will be SDL_CONTROLLER_BINDTYPE_NONE
.
|
extern |
Get the current state of a button on a game controller.
gamecontroller | a game controller. |
button | a button index (one of the SDL_GameControllerButton values). |
|
extern |
Convert a string into an SDL_GameControllerButton enum.
This function is called internally to translate SDL_GameController mapping strings for the underlying joystick device into the consistent SDL_GameController mapping. You do not normally need to call this function unless you are parsing SDL_GameController mappings in your own code.
str | string representing a SDL_GameController axis. |
SDL_CONTROLLER_AXIS_INVALID
if no match was found.
|
extern |
Get the firmware version of an opened controller, if available.
If the firmware version isn't available this function returns 0.
gamecontroller | the game controller object to query. |
|
extern |
Get the Joystick ID from a Game Controller.
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.
gamecontroller | the game controller object that you want to get a joystick from. |
|
extern |
Get the number of supported simultaneous fingers on a touchpad on a game controller.
|
extern |
Get the number of touchpads on a game controller.
|
extern |
Get the player index of an opened game controller.
For XInput controllers this returns the XInput user index.
gamecontroller | the game controller object to query. |
|
extern |
Get the USB product ID of an opened controller, if available.
If the product ID isn't available this function returns 0.
gamecontroller | the game controller object to query. |
|
extern |
Get the product version of an opened controller, if available.
If the product version isn't available this function returns 0.
gamecontroller | the game controller object to query. |
|
extern |
Get the current state of a game controller sensor.
The number of values and interpretation of the data is sensor dependent. See SDL_sensor.h for the details for each type of sensor.
gamecontroller | The controller to query. |
type | The type of sensor to query. |
data | A pointer filled with the current sensor state. |
num_values | The number of values to write to data. |
|
extern |
Get the data rate (number of events per second) of a game controller sensor.
gamecontroller | The controller to query. |
type | The type of sensor to query. |
|
extern |
Get the current state of a game controller sensor with the timestamp of the last update.
The number of values and interpretation of the data is sensor dependent. See SDL_sensor.h for the details for each type of sensor.
gamecontroller | The controller to query. |
type | The type of sensor to query. |
timestamp | A pointer filled with the timestamp in microseconds of the current sensor reading if available, or 0 if not. |
data | A pointer filled with the current sensor state. |
num_values | The number of values to write to data. |
|
extern |
Get the serial number of an opened controller, if available.
Returns the serial number of the controller, or NULL if it is not available.
gamecontroller | the game controller object to query. |
|
extern |
Get the Steam Input handle of an opened controller, if available.
Returns an InputHandle_t for the controller that can be used with Steam Input API: https://partner.steamgames.com/doc/api/ISteamInput
gamecontroller | the game controller object to query. |
|
extern |
Convert from an SDL_GameControllerAxis enum to a string.
The caller should not SDL_free() the returned string.
axis | an enum value for a given SDL_GameControllerAxis. |
|
extern |
Convert from an SDL_GameControllerButton enum to a string.
The caller should not SDL_free() the returned string.
button | an enum value for a given SDL_GameControllerButton. |
|
extern |
Get the current state of a finger on a touchpad on a game controller.
|
extern |
Get the type of this currently opened controller
This is the same name as returned by SDL_GameControllerTypeForIndex(), but it takes a controller identifier instead of the (unstable) device index.
gamecontroller | the game controller object to query. |
|
extern |
Get the USB vendor ID of an opened controller, if available.
If the vendor ID isn't available this function returns 0.
gamecontroller | the game controller object to query. |
|
extern |
Query whether a game controller has a given axis.
This merely reports whether the controller's mapping defined this axis, as that is all the information SDL has about the physical device.
gamecontroller | a game controller. |
axis | an axis enum value (an SDL_GameControllerAxis value). |
|
extern |
Query whether a game controller has a given button.
This merely reports whether the controller's mapping defined this button, as that is all the information SDL has about the physical device.
gamecontroller | a game controller. |
button | a button enum value (an SDL_GameControllerButton value). |
|
extern |
Query whether a game controller has an LED.
gamecontroller | The controller to query. |
|
extern |
Query whether a game controller has rumble support.
gamecontroller | The controller to query. |
|
extern |
Query whether a game controller has rumble support on triggers.
gamecontroller | The controller to query. |
|
extern |
Return whether a game controller has a particular sensor.
gamecontroller | The controller to query. |
type | The type of sensor to query. |
|
extern |
Query whether sensor data reporting is enabled for a game controller.
gamecontroller | The controller to query. |
type | The type of sensor to query. |
|
extern |
Get the current mapping of a Game Controller.
The returned string must be freed with SDL_free().
Details about mappings are discussed with SDL_GameControllerAddMapping().
gamecontroller | the game controller you want to get the current mapping for. |
|
extern |
Get the mapping of a game controller.
This can be called before any controllers are opened.
joystick_index | the device_index of a device, from zero to SDL_NumJoysticks()-1. |
|
extern |
Get the game controller mapping string for a given GUID.
The returned string must be freed with SDL_free().
guid | a structure containing the GUID for which a mapping is desired. |
|
extern |
Get the mapping at a particular index.
|
extern |
Get the implementation-dependent name for an opened game controller.
This is the same name as returned by SDL_GameControllerNameForIndex(), but it takes a controller identifier instead of the (unstable) device index.
gamecontroller | a game controller identifier previously returned by SDL_GameControllerOpen(). |
|
extern |
Get the implementation dependent name for the game controller.
This function can be called before any controllers are opened.
joystick_index
is the same as the device_index
passed to SDL_JoystickOpen().
joystick_index | the device_index of a device, from zero to SDL_NumJoysticks()-1. |
|
extern |
Get the number of mappings installed.
|
extern |
Open a game controller for use.
joystick_index
is the same as the device_index
passed to SDL_JoystickOpen().
The index passed as an argument refers to the N'th game controller on the system. This index is not the value which will identify this controller in future controller events. The joystick's instance id (SDL_JoystickID) will be used there instead.
joystick_index | the device_index of a device, up to SDL_NumJoysticks(). |
|
extern |
Get the implementation-dependent path for an opened game controller.
This is the same path as returned by SDL_GameControllerNameForIndex(), but it takes a controller identifier instead of the (unstable) device index.
gamecontroller | a game controller identifier previously returned by SDL_GameControllerOpen(). |
|
extern |
Get the implementation dependent path for the game controller.
This function can be called before any controllers are opened.
joystick_index
is the same as the device_index
passed to SDL_JoystickOpen().
joystick_index | the device_index of a device, from zero to SDL_NumJoysticks()-1. |
|
extern |
Start a rumble effect on a game controller.
Each call to this function cancels any previous rumble effect, and calling it with 0 intensity stops any rumbling.
gamecontroller | The controller to vibrate. |
low_frequency_rumble | The intensity of the low frequency (left) rumble motor, from 0 to 0xFFFF. |
high_frequency_rumble | The intensity of the high frequency (right) rumble motor, from 0 to 0xFFFF. |
duration_ms | The duration of the rumble effect, in milliseconds. |
|
extern |
Start a rumble effect in the game controller's triggers.
Each call to this function cancels any previous trigger rumble effect, and calling it with 0 intensity stops any rumbling.
Note that this is rumbling of the triggers and not the game controller as a whole. This is currently only supported on Xbox One controllers. If you want the (more common) whole-controller rumble, use SDL_GameControllerRumble() instead.
gamecontroller | The controller to vibrate. |
left_rumble | The intensity of the left trigger rumble motor, from 0 to 0xFFFF. |
right_rumble | The intensity of the right trigger rumble motor, from 0 to 0xFFFF. |
duration_ms | The duration of the rumble effect, in milliseconds. |
|
extern |
Send a controller specific effect packet
gamecontroller | The controller to affect. |
data | The data to send to the controller. |
size | The size of the data to send to the controller. |
|
extern |
Update a game controller's LED color.
gamecontroller | The controller to update. |
red | The intensity of the red LED. |
green | The intensity of the green LED. |
blue | The intensity of the blue LED. |
|
extern |
Set the player index of an opened game controller.
gamecontroller | the game controller object to adjust. |
player_index | Player index to assign to this controller, or -1 to clear the player index and turn off player LEDs. |
|
extern |
Set whether data reporting for a game controller sensor is enabled.
gamecontroller | The controller to update. |
type | The type of sensor to enable/disable. |
enabled | Whether data reporting should be enabled. |
|
extern |
Get the type of a game controller.
This can be called before any controllers are opened.
joystick_index | the device_index of a device, from zero to SDL_NumJoysticks()-1. |
|
extern |
Manually pump game controller updates if not using the loop.
This function is called automatically by the event loop if events are enabled. Under such circumstances, it will not be necessary to call this function.
|
extern |
Check if the given joystick is supported by the game controller interface.
joystick_index
is the same as the device_index
passed to SDL_JoystickOpen().
joystick_index | the device_index of a device, up to SDL_NumJoysticks(). |