SDL  2.0
SDL_joystick.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 /**
23  * \file SDL_joystick.h
24  *
25  * Include file for SDL joystick event handling
26  *
27  * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
28  * behind a device_index changing as joysticks are plugged and unplugged.
29  *
30  * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
31  * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
32  *
33  * The term "player_index" is the number assigned to a player on a specific
34  * controller. For XInput controllers this returns the XInput user index.
35  * Many joysticks will not be able to supply this information.
36  *
37  * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
38  * the device (a X360 wired controller for example). This identifier is platform dependent.
39  */
40 
41 #ifndef SDL_joystick_h_
42 #define SDL_joystick_h_
43 
44 #include "SDL_stdinc.h"
45 #include "SDL_error.h"
46 
47 #include "begin_code.h"
48 /* Set up for C function definitions, even when using C++ */
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /**
54  * \file SDL_joystick.h
55  *
56  * In order to use these functions, SDL_Init() must have been called
57  * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
58  * for joysticks, and load appropriate drivers.
59  *
60  * If you would like to receive joystick updates while the application
61  * is in the background, you should set the following hint before calling
62  * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
63  */
64 
65 /**
66  * The joystick structure used to identify an SDL joystick
67  */
68 struct _SDL_Joystick;
69 typedef struct _SDL_Joystick SDL_Joystick;
70 
71 /* A structure that encodes the stable unique id for a joystick device */
72 typedef struct {
73  Uint8 data[16];
75 
76 /**
77  * This is a unique ID for a joystick for the time it is connected to the system,
78  * and is never reused for the lifetime of the application. If the joystick is
79  * disconnected and reconnected, it will get a new ID.
80  *
81  * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
82  */
84 
85 typedef enum
86 {
98 
99 typedef enum
100 {
105  SDL_JOYSTICK_POWER_FULL, /* <= 100% */
109 
110 /* Set max recognized G-force from accelerometer
111  See src/joystick/uikit/SDL_sysjoystick.m for notes on why this is needed
112  */
113 #define SDL_IPHONE_MAX_GFORCE 5.0
114 
115 
116 /* Function prototypes */
117 
118 /**
119  * Locking for multi-threaded access to the joystick API
120  *
121  * If you are using the joystick API or handling events from multiple threads
122  * you should use these locking functions to protect access to the joysticks.
123  *
124  * In particular, you are guaranteed that the joystick list won't change, so
125  * the API functions that take a joystick index will be valid, and joystick
126  * and game controller events will not be delivered.
127  *
128  * \since This function is available since SDL 2.0.7.
129  */
130 extern DECLSPEC void SDLCALL SDL_LockJoysticks(void);
131 
132 
133 /**
134  * Unlocking for multi-threaded access to the joystick API
135  *
136  * If you are using the joystick API or handling events from multiple threads
137  * you should use these locking functions to protect access to the joysticks.
138  *
139  * In particular, you are guaranteed that the joystick list won't change, so
140  * the API functions that take a joystick index will be valid, and joystick
141  * and game controller events will not be delivered.
142  *
143  * \since This function is available since SDL 2.0.7.
144  */
145 extern DECLSPEC void SDLCALL SDL_UnlockJoysticks(void);
146 
147 /**
148  * Count the number of joysticks attached to the system.
149  *
150  * \returns the number of attached joysticks on success or a negative error
151  * code on failure; call SDL_GetError() for more information.
152  *
153  * \since This function is available since SDL 2.0.0.
154  *
155  * \sa SDL_JoystickName
156  * \sa SDL_JoystickPath
157  * \sa SDL_JoystickOpen
158  */
159 extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
160 
161 /**
162  * Get the implementation dependent name of a joystick.
163  *
164  * This can be called before any joysticks are opened.
165  *
166  * \param device_index the index of the joystick to query (the N'th joystick
167  * on the system)
168  * \returns the name of the selected joystick. If no name can be found, this
169  * function returns NULL; call SDL_GetError() for more information.
170  *
171  * \since This function is available since SDL 2.0.0.
172  *
173  * \sa SDL_JoystickName
174  * \sa SDL_JoystickOpen
175  */
176 extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
177 
178 /**
179  * Get the implementation dependent path of a joystick.
180  *
181  * This can be called before any joysticks are opened.
182  *
183  * \param device_index the index of the joystick to query (the N'th joystick
184  * on the system)
185  * \returns the path of the selected joystick. If no path can be found, this
186  * function returns NULL; call SDL_GetError() for more information.
187  *
188  * \since This function is available since SDL 2.0.24.
189  *
190  * \sa SDL_JoystickPath
191  * \sa SDL_JoystickOpen
192  */
193 extern DECLSPEC const char *SDLCALL SDL_JoystickPathForIndex(int device_index);
194 
195 /**
196  * Get the player index of a joystick, or -1 if it's not available This can be
197  * called before any joysticks are opened.
198  *
199  * \since This function is available since SDL 2.0.9.
200  */
201 extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
202 
203 /**
204  * Get the implementation-dependent GUID for the joystick at a given device
205  * index.
206  *
207  * This function can be called before any joysticks are opened.
208  *
209  * \param device_index the index of the joystick to query (the N'th joystick
210  * on the system
211  * \returns the GUID of the selected joystick. If called on an invalid index,
212  * this function returns a zero GUID
213  *
214  * \since This function is available since SDL 2.0.0.
215  *
216  * \sa SDL_JoystickGetGUID
217  * \sa SDL_JoystickGetGUIDString
218  */
219 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
220 
221 /**
222  * Get the USB vendor ID of a joystick, if available.
223  *
224  * This can be called before any joysticks are opened. If the vendor ID isn't
225  * available this function returns 0.
226  *
227  * \param device_index the index of the joystick to query (the N'th joystick
228  * on the system
229  * \returns the USB vendor ID of the selected joystick. If called on an
230  * invalid index, this function returns zero
231  *
232  * \since This function is available since SDL 2.0.6.
233  */
234 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceVendor(int device_index);
235 
236 /**
237  * Get the USB product ID of a joystick, if available.
238  *
239  * This can be called before any joysticks are opened. If the product ID isn't
240  * available this function returns 0.
241  *
242  * \param device_index the index of the joystick to query (the N'th joystick
243  * on the system
244  * \returns the USB product ID of the selected joystick. If called on an
245  * invalid index, this function returns zero
246  *
247  * \since This function is available since SDL 2.0.6.
248  */
249 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProduct(int device_index);
250 
251 /**
252  * Get the product version of a joystick, if available.
253  *
254  * This can be called before any joysticks are opened. If the product version
255  * isn't available this function returns 0.
256  *
257  * \param device_index the index of the joystick to query (the N'th joystick
258  * on the system
259  * \returns the product version of the selected joystick. If called on an
260  * invalid index, this function returns zero
261  *
262  * \since This function is available since SDL 2.0.6.
263  */
264 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetDeviceProductVersion(int device_index);
265 
266 /**
267  * Get the type of a joystick, if available.
268  *
269  * This can be called before any joysticks are opened.
270  *
271  * \param device_index the index of the joystick to query (the N'th joystick
272  * on the system
273  * \returns the SDL_JoystickType of the selected joystick. If called on an
274  * invalid index, this function returns `SDL_JOYSTICK_TYPE_UNKNOWN`
275  *
276  * \since This function is available since SDL 2.0.6.
277  */
278 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetDeviceType(int device_index);
279 
280 /**
281  * Get the instance ID of a joystick.
282  *
283  * This can be called before any joysticks are opened. If the index is out of
284  * range, this function will return -1.
285  *
286  * \param device_index the index of the joystick to query (the N'th joystick
287  * on the system
288  * \returns the instance id of the selected joystick. If called on an invalid
289  * index, this function returns zero
290  *
291  * \since This function is available since SDL 2.0.6.
292  */
293 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickGetDeviceInstanceID(int device_index);
294 
295 /**
296  * Open a joystick for use.
297  *
298  * The `device_index` argument refers to the N'th joystick presently
299  * recognized by SDL on the system. It is **NOT** the same as the instance ID
300  * used to identify the joystick in future events. See
301  * SDL_JoystickInstanceID() for more details about instance IDs.
302  *
303  * The joystick subsystem must be initialized before a joystick can be opened
304  * for use.
305  *
306  * \param device_index the index of the joystick to query
307  * \returns a joystick identifier or NULL if an error occurred; call
308  * SDL_GetError() for more information.
309  *
310  * \since This function is available since SDL 2.0.0.
311  *
312  * \sa SDL_JoystickClose
313  * \sa SDL_JoystickInstanceID
314  */
315 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
316 
317 /**
318  * Get the SDL_Joystick associated with an instance id.
319  *
320  * \param instance_id the instance id to get the SDL_Joystick for
321  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
322  * for more information.
323  *
324  * \since This function is available since SDL 2.0.4.
325  */
326 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID instance_id);
327 
328 /**
329  * Get the SDL_Joystick associated with a player index.
330  *
331  * \param player_index the player index to get the SDL_Joystick for
332  * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
333  * for more information.
334  *
335  * \since This function is available since SDL 2.0.12.
336  */
337 extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromPlayerIndex(int player_index);
338 
339 /**
340  * Attach a new virtual joystick.
341  *
342  * \returns the joystick's device index, or -1 if an error occurred.
343  *
344  * \since This function is available since SDL 2.0.14.
345  */
346 extern DECLSPEC int SDLCALL SDL_JoystickAttachVirtual(SDL_JoystickType type,
347  int naxes,
348  int nbuttons,
349  int nhats);
350 
351 /**
352  * Detach a virtual joystick.
353  *
354  * \param device_index a value previously returned from
355  * SDL_JoystickAttachVirtual()
356  * \returns 0 on success, or -1 if an error occurred.
357  *
358  * \since This function is available since SDL 2.0.14.
359  */
360 extern DECLSPEC int SDLCALL SDL_JoystickDetachVirtual(int device_index);
361 
362 /**
363  * Query whether or not the joystick at a given device index is virtual.
364  *
365  * \param device_index a joystick device index.
366  * \returns SDL_TRUE if the joystick is virtual, SDL_FALSE otherwise.
367  *
368  * \since This function is available since SDL 2.0.14.
369  */
370 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickIsVirtual(int device_index);
371 
372 /**
373  * Set values on an opened, virtual-joystick's axis.
374  *
375  * Please note that values set here will not be applied until the next call to
376  * SDL_JoystickUpdate, which can either be called directly, or can be called
377  * indirectly through various other SDL APIs, including, but not limited to
378  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
379  * SDL_WaitEvent.
380  *
381  * \param joystick the virtual joystick on which to set state.
382  * \param axis the specific axis on the virtual joystick to set.
383  * \param value the new value for the specified axis.
384  * \returns 0 on success, -1 on error.
385  *
386  * \since This function is available since SDL 2.0.14.
387  */
388 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
389 
390 /**
391  * Set values on an opened, virtual-joystick's button.
392  *
393  * Please note that values set here will not be applied until the next call to
394  * SDL_JoystickUpdate, which can either be called directly, or can be called
395  * indirectly through various other SDL APIs, including, but not limited to
396  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
397  * SDL_WaitEvent.
398  *
399  * \param joystick the virtual joystick on which to set state.
400  * \param button the specific button on the virtual joystick to set.
401  * \param value the new value for the specified button.
402  * \returns 0 on success, -1 on error.
403  *
404  * \since This function is available since SDL 2.0.14.
405  */
406 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
407 
408 /**
409  * Set values on an opened, virtual-joystick's hat.
410  *
411  * Please note that values set here will not be applied until the next call to
412  * SDL_JoystickUpdate, which can either be called directly, or can be called
413  * indirectly through various other SDL APIs, including, but not limited to
414  * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
415  * SDL_WaitEvent.
416  *
417  * \param joystick the virtual joystick on which to set state.
418  * \param hat the specific hat on the virtual joystick to set.
419  * \param value the new value for the specified hat.
420  * \returns 0 on success, -1 on error.
421  *
422  * \since This function is available since SDL 2.0.14.
423  */
424 extern DECLSPEC int SDLCALL SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
425 
426 /**
427  * Get the implementation dependent name of a joystick.
428  *
429  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
430  * \returns the name of the selected joystick. If no name can be found, this
431  * function returns NULL; call SDL_GetError() for more information.
432  *
433  * \since This function is available since SDL 2.0.0.
434  *
435  * \sa SDL_JoystickNameForIndex
436  * \sa SDL_JoystickOpen
437  */
438 extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick *joystick);
439 
440 /**
441  * Get the implementation dependent path of a joystick.
442  *
443  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
444  * \returns the path of the selected joystick. If no path can be found, this
445  * function returns NULL; call SDL_GetError() for more information.
446  *
447  * \since This function is available since SDL 2.0.24.
448  *
449  * \sa SDL_JoystickPathForIndex
450  */
451 extern DECLSPEC const char *SDLCALL SDL_JoystickPath(SDL_Joystick *joystick);
452 
453 /**
454  * Get the player index of an opened joystick.
455  *
456  * For XInput controllers this returns the XInput user index. Many joysticks
457  * will not be able to supply this information.
458  *
459  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
460  * \returns the player index, or -1 if it's not available.
461  *
462  * \since This function is available since SDL 2.0.9.
463  */
464 extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick);
465 
466 /**
467  * Set the player index of an opened joystick.
468  *
469  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
470  * \param player_index the player index to set.
471  *
472  * \since This function is available since SDL 2.0.12.
473  */
474 extern DECLSPEC void SDLCALL SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index);
475 
476 /**
477  * Get the implementation-dependent GUID for the joystick.
478  *
479  * This function requires an open joystick.
480  *
481  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
482  * \returns the GUID of the given joystick. If called on an invalid index,
483  * this function returns a zero GUID; call SDL_GetError() for more
484  * information.
485  *
486  * \since This function is available since SDL 2.0.0.
487  *
488  * \sa SDL_JoystickGetDeviceGUID
489  * \sa SDL_JoystickGetGUIDString
490  */
491 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick *joystick);
492 
493 /**
494  * Get the USB vendor ID of an opened joystick, if available.
495  *
496  * If the vendor ID isn't available this function returns 0.
497  *
498  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
499  * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
500  *
501  * \since This function is available since SDL 2.0.6.
502  */
503 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetVendor(SDL_Joystick *joystick);
504 
505 /**
506  * Get the USB product ID of an opened joystick, if available.
507  *
508  * If the product ID isn't available this function returns 0.
509  *
510  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
511  * \returns the USB product ID of the selected joystick, or 0 if unavailable.
512  *
513  * \since This function is available since SDL 2.0.6.
514  */
515 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProduct(SDL_Joystick *joystick);
516 
517 /**
518  * Get the product version of an opened joystick, if available.
519  *
520  * If the product version isn't available this function returns 0.
521  *
522  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
523  * \returns the product version of the selected joystick, or 0 if unavailable.
524  *
525  * \since This function is available since SDL 2.0.6.
526  */
527 extern DECLSPEC Uint16 SDLCALL SDL_JoystickGetProductVersion(SDL_Joystick *joystick);
528 
529 /**
530  * Get the serial number of an opened joystick, if available.
531  *
532  * Returns the serial number of the joystick, or NULL if it is not available.
533  *
534  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
535  * \returns the serial number of the selected joystick, or NULL if
536  * unavailable.
537  *
538  * \since This function is available since SDL 2.0.14.
539  */
540 extern DECLSPEC const char * SDLCALL SDL_JoystickGetSerial(SDL_Joystick *joystick);
541 
542 /**
543  * Get the type of an opened joystick.
544  *
545  * \param joystick the SDL_Joystick obtained from SDL_JoystickOpen()
546  * \returns the SDL_JoystickType of the selected joystick.
547  *
548  * \since This function is available since SDL 2.0.6.
549  */
550 extern DECLSPEC SDL_JoystickType SDLCALL SDL_JoystickGetType(SDL_Joystick *joystick);
551 
552 /**
553  * Get an ASCII string representation for a given SDL_JoystickGUID.
554  *
555  * You should supply at least 33 bytes for pszGUID.
556  *
557  * \param guid the SDL_JoystickGUID you wish to convert to string
558  * \param pszGUID buffer in which to write the ASCII string
559  * \param cbGUID the size of pszGUID
560  *
561  * \since This function is available since SDL 2.0.0.
562  *
563  * \sa SDL_JoystickGetDeviceGUID
564  * \sa SDL_JoystickGetGUID
565  * \sa SDL_JoystickGetGUIDFromString
566  */
567 extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
568 
569 /**
570  * Convert a GUID string into a SDL_JoystickGUID structure.
571  *
572  * Performs no error checking. If this function is given a string containing
573  * an invalid GUID, the function will silently succeed, but the GUID generated
574  * will not be useful.
575  *
576  * \param pchGUID string containing an ASCII representation of a GUID
577  * \returns a SDL_JoystickGUID structure.
578  *
579  * \since This function is available since SDL 2.0.0.
580  *
581  * \sa SDL_JoystickGetGUIDString
582  */
583 extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
584 
585 /**
586  * Get the status of a specified joystick.
587  *
588  * \param joystick the joystick to query
589  * \returns SDL_TRUE if the joystick has been opened, SDL_FALSE if it has not;
590  * call SDL_GetError() for more information.
591  *
592  * \since This function is available since SDL 2.0.0.
593  *
594  * \sa SDL_JoystickClose
595  * \sa SDL_JoystickOpen
596  */
597 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick *joystick);
598 
599 /**
600  * Get the instance ID of an opened joystick.
601  *
602  * \param joystick an SDL_Joystick structure containing joystick information
603  * \returns the instance ID of the specified joystick on success or a negative
604  * error code on failure; call SDL_GetError() for more information.
605  *
606  * \since This function is available since SDL 2.0.0.
607  *
608  * \sa SDL_JoystickOpen
609  */
610 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick *joystick);
611 
612 /**
613  * Get the number of general axis controls on a joystick.
614  *
615  * Often, the directional pad on a game controller will either look like 4
616  * separate buttons or a POV hat, and not axes, but all of this is up to the
617  * device and platform.
618  *
619  * \param joystick an SDL_Joystick structure containing joystick information
620  * \returns the number of axis controls/number of axes on success or a
621  * negative error code on failure; call SDL_GetError() for more
622  * information.
623  *
624  * \since This function is available since SDL 2.0.0.
625  *
626  * \sa SDL_JoystickGetAxis
627  * \sa SDL_JoystickOpen
628  */
629 extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick *joystick);
630 
631 /**
632  * Get the number of trackballs on a joystick.
633  *
634  * Joystick trackballs have only relative motion events associated with them
635  * and their state cannot be polled.
636  *
637  * Most joysticks do not have trackballs.
638  *
639  * \param joystick an SDL_Joystick structure containing joystick information
640  * \returns the number of trackballs on success or a negative error code on
641  * failure; call SDL_GetError() for more information.
642  *
643  * \since This function is available since SDL 2.0.0.
644  *
645  * \sa SDL_JoystickGetBall
646  */
647 extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick *joystick);
648 
649 /**
650  * Get the number of POV hats on a joystick.
651  *
652  * \param joystick an SDL_Joystick structure containing joystick information
653  * \returns the number of POV hats on success or a negative error code on
654  * failure; call SDL_GetError() for more information.
655  *
656  * \since This function is available since SDL 2.0.0.
657  *
658  * \sa SDL_JoystickGetHat
659  * \sa SDL_JoystickOpen
660  */
661 extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick *joystick);
662 
663 /**
664  * Get the number of buttons on a joystick.
665  *
666  * \param joystick an SDL_Joystick structure containing joystick information
667  * \returns the number of buttons on success or a negative error code on
668  * failure; call SDL_GetError() for more information.
669  *
670  * \since This function is available since SDL 2.0.0.
671  *
672  * \sa SDL_JoystickGetButton
673  * \sa SDL_JoystickOpen
674  */
675 extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick *joystick);
676 
677 /**
678  * Update the current state of the open joysticks.
679  *
680  * This is called automatically by the event loop if any joystick events are
681  * enabled.
682  *
683  * \since This function is available since SDL 2.0.0.
684  *
685  * \sa SDL_JoystickEventState
686  */
687 extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
688 
689 /**
690  * Enable/disable joystick event polling.
691  *
692  * If joystick events are disabled, you must call SDL_JoystickUpdate()
693  * yourself and manually check the state of the joystick when you want
694  * joystick information.
695  *
696  * It is recommended that you leave joystick event handling enabled.
697  *
698  * **WARNING**: Calling this function may delete all events currently in SDL's
699  * event queue.
700  *
701  * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`
702  * \returns 1 if enabled, 0 if disabled, or a negative error code on failure;
703  * call SDL_GetError() for more information.
704  *
705  * If `state` is `SDL_QUERY` then the current state is returned,
706  * otherwise the new processing state is returned.
707  *
708  * \since This function is available since SDL 2.0.0.
709  *
710  * \sa SDL_GameControllerEventState
711  */
712 extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
713 
714 #define SDL_JOYSTICK_AXIS_MAX 32767
715 #define SDL_JOYSTICK_AXIS_MIN -32768
716 
717 /**
718  * Get the current state of an axis control on a joystick.
719  *
720  * SDL makes no promises about what part of the joystick any given axis refers
721  * to. Your game should have some sort of configuration UI to let users
722  * specify what each axis should be bound to. Alternately, SDL's higher-level
723  * Game Controller API makes a great effort to apply order to this lower-level
724  * interface, so you know that a specific axis is the "left thumb stick," etc.
725  *
726  * The value returned by SDL_JoystickGetAxis() is a signed integer (-32768 to
727  * 32767) representing the current position of the axis. It may be necessary
728  * to impose certain tolerances on these values to account for jitter.
729  *
730  * \param joystick an SDL_Joystick structure containing joystick information
731  * \param axis the axis to query; the axis indices start at index 0
732  * \returns a 16-bit signed integer representing the current position of the
733  * axis or 0 on failure; call SDL_GetError() for more information.
734  *
735  * \since This function is available since SDL 2.0.0.
736  *
737  * \sa SDL_JoystickNumAxes
738  */
739 extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick *joystick,
740  int axis);
741 
742 /**
743  * Get the initial state of an axis control on a joystick.
744  *
745  * The state is a value ranging from -32768 to 32767.
746  *
747  * The axis indices start at index 0.
748  *
749  * \param joystick an SDL_Joystick structure containing joystick information
750  * \param axis the axis to query; the axis indices start at index 0
751  * \param state Upon return, the initial value is supplied here.
752  * \return SDL_TRUE if this axis has any initial value, or SDL_FALSE if not.
753  *
754  * \since This function is available since SDL 2.0.6.
755  */
756 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick,
757  int axis, Sint16 *state);
758 
759 /**
760  * \name Hat positions
761  */
762 /* @{ */
763 #define SDL_HAT_CENTERED 0x00
764 #define SDL_HAT_UP 0x01
765 #define SDL_HAT_RIGHT 0x02
766 #define SDL_HAT_DOWN 0x04
767 #define SDL_HAT_LEFT 0x08
768 #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
769 #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
770 #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
771 #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
772 /* @} */
773 
774 /**
775  * Get the current state of a POV hat on a joystick.
776  *
777  * The returned value will be one of the following positions:
778  *
779  * - `SDL_HAT_CENTERED`
780  * - `SDL_HAT_UP`
781  * - `SDL_HAT_RIGHT`
782  * - `SDL_HAT_DOWN`
783  * - `SDL_HAT_LEFT`
784  * - `SDL_HAT_RIGHTUP`
785  * - `SDL_HAT_RIGHTDOWN`
786  * - `SDL_HAT_LEFTUP`
787  * - `SDL_HAT_LEFTDOWN`
788  *
789  * \param joystick an SDL_Joystick structure containing joystick information
790  * \param hat the hat index to get the state from; indices start at index 0
791  * \returns the current hat position.
792  *
793  * \since This function is available since SDL 2.0.0.
794  *
795  * \sa SDL_JoystickNumHats
796  */
797 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick *joystick,
798  int hat);
799 
800 /**
801  * Get the ball axis change since the last poll.
802  *
803  * Trackballs can only return relative motion since the last call to
804  * SDL_JoystickGetBall(), these motion deltas are placed into `dx` and `dy`.
805  *
806  * Most joysticks do not have trackballs.
807  *
808  * \param joystick the SDL_Joystick to query
809  * \param ball the ball index to query; ball indices start at index 0
810  * \param dx stores the difference in the x axis position since the last poll
811  * \param dy stores the difference in the y axis position since the last poll
812  * \returns 0 on success or a negative error code on failure; call
813  * SDL_GetError() for more information.
814  *
815  * \since This function is available since SDL 2.0.0.
816  *
817  * \sa SDL_JoystickNumBalls
818  */
819 extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick *joystick,
820  int ball, int *dx, int *dy);
821 
822 /**
823  * Get the current state of a button on a joystick.
824  *
825  * \param joystick an SDL_Joystick structure containing joystick information
826  * \param button the button index to get the state from; indices start at
827  * index 0
828  * \returns 1 if the specified button is pressed, 0 otherwise.
829  *
830  * \since This function is available since SDL 2.0.0.
831  *
832  * \sa SDL_JoystickNumButtons
833  */
834 extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick *joystick,
835  int button);
836 
837 /**
838  * Start a rumble effect.
839  *
840  * Each call to this function cancels any previous rumble effect, and calling
841  * it with 0 intensity stops any rumbling.
842  *
843  * \param joystick The joystick to vibrate
844  * \param low_frequency_rumble The intensity of the low frequency (left)
845  * rumble motor, from 0 to 0xFFFF
846  * \param high_frequency_rumble The intensity of the high frequency (right)
847  * rumble motor, from 0 to 0xFFFF
848  * \param duration_ms The duration of the rumble effect, in milliseconds
849  * \returns 0, or -1 if rumble isn't supported on this joystick
850  *
851  * \since This function is available since SDL 2.0.9.
852  *
853  * \sa SDL_JoystickHasRumble
854  */
855 extern DECLSPEC int SDLCALL SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
856 
857 /**
858  * Start a rumble effect in the joystick's triggers
859  *
860  * Each call to this function cancels any previous trigger rumble effect, and
861  * calling it with 0 intensity stops any rumbling.
862  *
863  * Note that this is rumbling of the _triggers_ and not the game controller as
864  * a whole. This is currently only supported on Xbox One controllers. If you
865  * want the (more common) whole-controller rumble, use SDL_JoystickRumble()
866  * instead.
867  *
868  * \param joystick The joystick to vibrate
869  * \param left_rumble The intensity of the left trigger rumble motor, from 0
870  * to 0xFFFF
871  * \param right_rumble The intensity of the right trigger rumble motor, from 0
872  * to 0xFFFF
873  * \param duration_ms The duration of the rumble effect, in milliseconds
874  * \returns 0, or -1 if trigger rumble isn't supported on this joystick
875  *
876  * \since This function is available since SDL 2.0.14.
877  *
878  * \sa SDL_JoystickHasRumbleTriggers
879  */
880 extern DECLSPEC int SDLCALL SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
881 
882 /**
883  * Query whether a joystick has an LED.
884  *
885  * An example of a joystick LED is the light on the back of a PlayStation 4's
886  * DualShock 4 controller.
887  *
888  * \param joystick The joystick to query
889  * \return SDL_TRUE if the joystick has a modifiable LED, SDL_FALSE otherwise.
890  *
891  * \since This function is available since SDL 2.0.14.
892  */
893 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasLED(SDL_Joystick *joystick);
894 
895 /**
896  * Query whether a joystick has rumble support.
897  *
898  * \param joystick The joystick to query
899  * \return SDL_TRUE if the joystick has rumble, SDL_FALSE otherwise.
900  *
901  * \since This function is available since SDL 2.0.18.
902  *
903  * \sa SDL_JoystickRumble
904  */
905 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumble(SDL_Joystick *joystick);
906 
907 /**
908  * Query whether a joystick has rumble support on triggers.
909  *
910  * \param joystick The joystick to query
911  * \return SDL_TRUE if the joystick has trigger rumble, SDL_FALSE otherwise.
912  *
913  * \since This function is available since SDL 2.0.18.
914  *
915  * \sa SDL_JoystickRumbleTriggers
916  */
917 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick);
918 
919 /**
920  * Update a joystick's LED color.
921  *
922  * An example of a joystick LED is the light on the back of a PlayStation 4's
923  * DualShock 4 controller.
924  *
925  * \param joystick The joystick to update
926  * \param red The intensity of the red LED
927  * \param green The intensity of the green LED
928  * \param blue The intensity of the blue LED
929  * \returns 0 on success, -1 if this joystick does not have a modifiable LED
930  *
931  * \since This function is available since SDL 2.0.14.
932  */
933 extern DECLSPEC int SDLCALL SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
934 
935 /**
936  * Send a joystick specific effect packet
937  *
938  * \param joystick The joystick to affect
939  * \param data The data to send to the joystick
940  * \param size The size of the data to send to the joystick
941  * \returns 0, or -1 if this joystick or driver doesn't support effect packets
942  *
943  * \since This function is available since SDL 2.0.16.
944  */
945 extern DECLSPEC int SDLCALL SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size);
946 
947 /**
948  * Close a joystick previously opened with SDL_JoystickOpen().
949  *
950  * \param joystick The joystick device to close
951  *
952  * \since This function is available since SDL 2.0.0.
953  *
954  * \sa SDL_JoystickOpen
955  */
956 extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick *joystick);
957 
958 /**
959  * Get the battery level of a joystick as SDL_JoystickPowerLevel.
960  *
961  * \param joystick the SDL_Joystick to query
962  * \returns the current battery level as SDL_JoystickPowerLevel on success or
963  * `SDL_JOYSTICK_POWER_UNKNOWN` if it is unknown
964  *
965  * \since This function is available since SDL 2.0.4.
966  */
968 
969 /* Ends C function definitions when using C++ */
970 #ifdef __cplusplus
971 }
972 #endif
973 #include "close_code.h"
974 
975 #endif /* SDL_joystick_h_ */
976 
977 /* vi: set ts=4 sw=4 expandtab: */
SDL_bool SDL_JoystickGetAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state)
SDL_JoystickType
Definition: SDL_joystick.h:86
@ SDL_JOYSTICK_TYPE_DANCE_PAD
Definition: SDL_joystick.h:92
@ SDL_JOYSTICK_TYPE_ARCADE_PAD
Definition: SDL_joystick.h:95
@ SDL_JOYSTICK_TYPE_UNKNOWN
Definition: SDL_joystick.h:87
@ SDL_JOYSTICK_TYPE_ARCADE_STICK
Definition: SDL_joystick.h:90
@ SDL_JOYSTICK_TYPE_WHEEL
Definition: SDL_joystick.h:89
@ SDL_JOYSTICK_TYPE_THROTTLE
Definition: SDL_joystick.h:96
@ SDL_JOYSTICK_TYPE_GUITAR
Definition: SDL_joystick.h:93
@ SDL_JOYSTICK_TYPE_FLIGHT_STICK
Definition: SDL_joystick.h:91
@ SDL_JOYSTICK_TYPE_GAMECONTROLLER
Definition: SDL_joystick.h:88
@ SDL_JOYSTICK_TYPE_DRUM_KIT
Definition: SDL_joystick.h:94
SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
Uint16 SDL_JoystickGetProductVersion(SDL_Joystick *joystick)
int SDL_JoystickGetPlayerIndex(SDL_Joystick *joystick)
struct _SDL_Joystick SDL_Joystick
Definition: SDL_joystick.h:69
int SDL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
SDL_JoystickID SDL_JoystickInstanceID(SDL_Joystick *joystick)
int SDL_JoystickSetVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value)
SDL_JoystickPowerLevel
Definition: SDL_joystick.h:100
@ SDL_JOYSTICK_POWER_MAX
Definition: SDL_joystick.h:107
@ SDL_JOYSTICK_POWER_FULL
Definition: SDL_joystick.h:105
@ SDL_JOYSTICK_POWER_MEDIUM
Definition: SDL_joystick.h:104
@ SDL_JOYSTICK_POWER_EMPTY
Definition: SDL_joystick.h:102
@ SDL_JOYSTICK_POWER_UNKNOWN
Definition: SDL_joystick.h:101
@ SDL_JOYSTICK_POWER_WIRED
Definition: SDL_joystick.h:106
@ SDL_JOYSTICK_POWER_LOW
Definition: SDL_joystick.h:103
const char * SDL_JoystickName(SDL_Joystick *joystick)
SDL_bool SDL_JoystickHasLED(SDL_Joystick *joystick)
int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick)
SDL_bool SDL_JoystickIsVirtual(int device_index)
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:83
int SDL_JoystickSetVirtualButton(SDL_Joystick *joystick, int button, Uint8 value)
int SDL_NumJoysticks(void)
void SDL_JoystickSetPlayerIndex(SDL_Joystick *joystick, int player_index)
Uint16 SDL_JoystickGetDeviceProduct(int device_index)
Uint16 SDL_JoystickGetDeviceProductVersion(int device_index)
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
const char * SDL_JoystickPath(SDL_Joystick *joystick)
Uint16 SDL_JoystickGetDeviceVendor(int device_index)
int SDL_JoystickNumBalls(SDL_Joystick *joystick)
SDL_bool SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
int SDL_JoystickNumHats(SDL_Joystick *joystick)
int SDL_JoystickSetVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
void SDL_JoystickClose(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick *joystick)
SDL_bool SDL_JoystickHasRumble(SDL_Joystick *joystick)
int SDL_JoystickGetDevicePlayerIndex(int device_index)
int SDL_JoystickDetachVirtual(int device_index)
SDL_bool SDL_JoystickGetAttached(SDL_Joystick *joystick)
Uint16 SDL_JoystickGetProduct(SDL_Joystick *joystick)
void SDL_LockJoysticks(void)
const char * SDL_JoystickGetSerial(SDL_Joystick *joystick)
SDL_Joystick * SDL_JoystickOpen(int device_index)
Uint16 SDL_JoystickGetVendor(SDL_Joystick *joystick)
const char * SDL_JoystickPathForIndex(int device_index)
SDL_JoystickType SDL_JoystickGetType(SDL_Joystick *joystick)
int SDL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
int SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nbuttons, int nhats)
void SDL_UnlockJoysticks(void)
Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
void SDL_JoystickUpdate(void)
int SDL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
int SDL_JoystickEventState(int state)
SDL_JoystickType SDL_JoystickGetDeviceType(int device_index)
int SDL_JoystickNumAxes(SDL_Joystick *joystick)
int SDL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size)
SDL_Joystick * SDL_JoystickFromInstanceID(SDL_JoystickID instance_id)
Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)
const char * SDL_JoystickNameForIndex(int device_index)
int SDL_JoystickNumButtons(SDL_Joystick *joystick)
SDL_Joystick * SDL_JoystickFromPlayerIndex(int player_index)
uint8_t Uint8
Definition: SDL_stdinc.h:196
uint16_t Uint16
Definition: SDL_stdinc.h:208
int32_t Sint32
Definition: SDL_stdinc.h:214
SDL_bool
Definition: SDL_stdinc.h:179
int16_t Sint16
Definition: SDL_stdinc.h:202
uint32_t Uint32
Definition: SDL_stdinc.h:220