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