SDL 3.0
SDL_joystick.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 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 * # CategoryJoystick
24 *
25 * SDL joystick support.
26 *
27 * This is the lower-level joystick handling. If you want the simpler option,
28 * where what each button does is well-defined, you should use the gamepad API
29 * instead.
30 *
31 * The term "instance_id" is the current instantiation of a joystick device in
32 * the system. If the joystick is removed and then re-inserted then it will
33 * get a new instance_id. instance_id's are monotonically increasing
34 * identifiers of a joystick plugged in.
35 *
36 * The term "player_index" is the number assigned to a player on a specific
37 * controller. For XInput controllers this returns the XInput user index. Many
38 * joysticks will not be able to supply this information.
39 *
40 * SDL_GUID is used as a stable 128-bit identifier for a joystick device that
41 * does not change over time. It identifies class of the device (a X360 wired
42 * controller for example). This identifier is platform dependent.
43 *
44 * In order to use these functions, SDL_Init() must have been called with the
45 * SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks,
46 * and load appropriate drivers.
47 *
48 * If you would like to receive joystick updates while the application is in
49 * the background, you should set the following hint before calling
50 * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
51 *
52 * SDL can provide virtual joysticks as well: the app defines an imaginary
53 * controller with SDL_AttachVirtualJoystick(), and then can provide inputs
54 * for it via SDL_SetJoystickVirtualAxis(), SDL_SetJoystickVirtualButton(),
55 * etc. As this data is supplied, it will look like a normal joystick to SDL,
56 * just not backed by a hardware driver. This has been used to make unusual
57 * devices, like VR headset controllers, look like normal joysticks, or
58 * provide recording/playback of game inputs, etc.
59 */
60
61#ifndef SDL_joystick_h_
62#define SDL_joystick_h_
63
64#include <SDL3/SDL_stdinc.h>
65#include <SDL3/SDL_error.h>
66#include <SDL3/SDL_guid.h>
67#include <SDL3/SDL_mutex.h>
68#include <SDL3/SDL_power.h>
69#include <SDL3/SDL_properties.h>
70#include <SDL3/SDL_sensor.h>
71
72#include <SDL3/SDL_begin_code.h>
73/* Set up for C function definitions, even when using C++ */
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78#ifdef SDL_THREAD_SAFETY_ANALYSIS
79/*
80 * This is not an exported symbol from SDL, this is only in the headers to
81 * help Clang's thread safety analysis tools to function. Do not attempt
82 * to access this symbol from your app, it will not work!
83 */
84extern SDL_Mutex *SDL_joystick_lock;
85#endif
86
87/**
88 * The joystick structure used to identify an SDL joystick.
89 *
90 * This is opaque data.
91 *
92 * \since This struct is available since SDL 3.2.0.
93 */
95
96/**
97 * This is a unique ID for a joystick for the time it is connected to the
98 * system, and is never reused for the lifetime of the application.
99 *
100 * If the joystick is disconnected and reconnected, it will get a new ID.
101 *
102 * The value 0 is an invalid ID.
103 *
104 * \since This datatype is available since SDL 3.2.0.
105 */
107
108/**
109 * An enum of some common joystick types.
110 *
111 * In some cases, SDL can identify a low-level joystick as being a certain
112 * type of device, and will report it through SDL_GetJoystickType (or
113 * SDL_GetJoystickTypeForID).
114 *
115 * This is by no means a complete list of everything that can be plugged into
116 * a computer.
117 *
118 * You may refer to
119 * [XInput Controller Types](https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes)
120 * table for a general understanding of each joystick type.
121 *
122 * \since This enum is available since SDL 3.2.0.
123 */
138
139/**
140 * Possible connection states for a joystick device.
141 *
142 * This is used by SDL_GetJoystickConnectionState to report how a device is
143 * connected to the system.
144 *
145 * \since This enum is available since SDL 3.2.0.
146 */
154
155/**
156 * The largest value an SDL_Joystick's axis can report.
157 *
158 * \since This macro is available since SDL 3.2.0.
159 *
160 * \sa SDL_JOYSTICK_AXIS_MIN
161 */
162#define SDL_JOYSTICK_AXIS_MAX 32767
163
164/**
165 * The smallest value an SDL_Joystick's axis can report.
166 *
167 * This is a negative number!
168 *
169 * \since This macro is available since SDL 3.2.0.
170 *
171 * \sa SDL_JOYSTICK_AXIS_MAX
172 */
173#define SDL_JOYSTICK_AXIS_MIN -32768
174
175
176/* Function prototypes */
177
178/**
179 * Locking for atomic access to the joystick API.
180 *
181 * The SDL joystick functions are thread-safe, however you can lock the
182 * joysticks while processing to guarantee that the joystick list won't change
183 * and joystick and gamepad events will not be delivered.
184 *
185 * \since This function is available since SDL 3.2.0.
186 */
187extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
188
189/**
190 * Unlocking for atomic access to the joystick API.
191 *
192 * \since This function is available since SDL 3.2.0.
193 */
194extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
195
196/**
197 * Return whether a joystick is currently connected.
198 *
199 * \returns true if a joystick is connected, false otherwise.
200 *
201 * \since This function is available since SDL 3.2.0.
202 *
203 * \sa SDL_GetJoysticks
204 */
205extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void);
206
207/**
208 * Get a list of currently connected joysticks.
209 *
210 * \param count a pointer filled in with the number of joysticks returned, may
211 * be NULL.
212 * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
213 * call SDL_GetError() for more information. This should be freed
214 * with SDL_free() when it is no longer needed.
215 *
216 * \since This function is available since SDL 3.2.0.
217 *
218 * \sa SDL_HasJoystick
219 * \sa SDL_OpenJoystick
220 */
221extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
222
223/**
224 * Get the implementation dependent name of a joystick.
225 *
226 * This can be called before any joysticks are opened.
227 *
228 * \param instance_id the joystick instance ID.
229 * \returns the name of the selected joystick. If no name can be found, this
230 * function returns NULL; call SDL_GetError() for more information.
231 *
232 * \since This function is available since SDL 3.2.0.
233 *
234 * \sa SDL_GetJoystickName
235 * \sa SDL_GetJoysticks
236 */
237extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
238
239/**
240 * Get the implementation dependent path of a joystick.
241 *
242 * This can be called before any joysticks are opened.
243 *
244 * \param instance_id the joystick instance ID.
245 * \returns the path of the selected joystick. If no path can be found, this
246 * function returns NULL; call SDL_GetError() for more information.
247 *
248 * \since This function is available since SDL 3.2.0.
249 *
250 * \sa SDL_GetJoystickPath
251 * \sa SDL_GetJoysticks
252 */
253extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
254
255/**
256 * Get the player index of a joystick.
257 *
258 * This can be called before any joysticks are opened.
259 *
260 * \param instance_id the joystick instance ID.
261 * \returns the player index of a joystick, or -1 if it's not available.
262 *
263 * \since This function is available since SDL 3.2.0.
264 *
265 * \sa SDL_GetJoystickPlayerIndex
266 * \sa SDL_GetJoysticks
267 */
268extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id);
269
270/**
271 * Get the implementation-dependent GUID of a joystick.
272 *
273 * This can be called before any joysticks are opened.
274 *
275 * \param instance_id the joystick instance ID.
276 * \returns the GUID of the selected joystick. If called with an invalid
277 * instance_id, this function returns a zero GUID.
278 *
279 * \since This function is available since SDL 3.2.0.
280 *
281 * \sa SDL_GetJoystickGUID
282 * \sa SDL_GUIDToString
283 */
284extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);
285
286/**
287 * Get the USB vendor ID of a joystick, if available.
288 *
289 * This can be called before any joysticks are opened. If the vendor ID isn't
290 * available this function returns 0.
291 *
292 * \param instance_id the joystick instance ID.
293 * \returns the USB vendor ID of the selected joystick. If called with an
294 * invalid instance_id, this function returns 0.
295 *
296 * \since This function is available since SDL 3.2.0.
297 *
298 * \sa SDL_GetJoystickVendor
299 * \sa SDL_GetJoysticks
300 */
301extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id);
302
303/**
304 * Get the USB product ID of a joystick, if available.
305 *
306 * This can be called before any joysticks are opened. If the product ID isn't
307 * available this function returns 0.
308 *
309 * \param instance_id the joystick instance ID.
310 * \returns the USB product ID of the selected joystick. If called with an
311 * invalid instance_id, this function returns 0.
312 *
313 * \since This function is available since SDL 3.2.0.
314 *
315 * \sa SDL_GetJoystickProduct
316 * \sa SDL_GetJoysticks
317 */
318extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id);
319
320/**
321 * Get the product version of a joystick, if available.
322 *
323 * This can be called before any joysticks are opened. If the product version
324 * isn't available this function returns 0.
325 *
326 * \param instance_id the joystick instance ID.
327 * \returns the product version of the selected joystick. If called with an
328 * invalid instance_id, this function returns 0.
329 *
330 * \since This function is available since SDL 3.2.0.
331 *
332 * \sa SDL_GetJoystickProductVersion
333 * \sa SDL_GetJoysticks
334 */
335extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id);
336
337/**
338 * Get the type of a joystick, if available.
339 *
340 * This can be called before any joysticks are opened.
341 *
342 * \param instance_id the joystick instance ID.
343 * \returns the SDL_JoystickType of the selected joystick. If called with an
344 * invalid instance_id, this function returns
345 * `SDL_JOYSTICK_TYPE_UNKNOWN`.
346 *
347 * \since This function is available since SDL 3.2.0.
348 *
349 * \sa SDL_GetJoystickType
350 * \sa SDL_GetJoysticks
351 */
352extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id);
353
354/**
355 * Open a joystick for use.
356 *
357 * The joystick subsystem must be initialized before a joystick can be opened
358 * for use.
359 *
360 * \param instance_id the joystick instance ID.
361 * \returns a joystick identifier or NULL on failure; call SDL_GetError() for
362 * more information.
363 *
364 * \since This function is available since SDL 3.2.0.
365 *
366 * \sa SDL_CloseJoystick
367 */
368extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
369
370/**
371 * Get the SDL_Joystick associated with an instance ID, if it has been opened.
372 *
373 * \param instance_id the instance ID to get the SDL_Joystick for.
374 * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
375 * opened yet; call SDL_GetError() for more information.
376 *
377 * \since This function is available since SDL 3.2.0.
378 */
379extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
380
381/**
382 * Get the SDL_Joystick associated with a player index.
383 *
384 * \param player_index the player index to get the SDL_Joystick for.
385 * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
386 * for more information.
387 *
388 * \since This function is available since SDL 3.2.0.
389 *
390 * \sa SDL_GetJoystickPlayerIndex
391 * \sa SDL_SetJoystickPlayerIndex
392 */
393extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
394
395/**
396 * The structure that describes a virtual joystick touchpad.
397 *
398 * \since This struct is available since SDL 3.2.0.
399 *
400 * \sa SDL_VirtualJoystickDesc
401 */
403{
404 Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */
407
408/**
409 * The structure that describes a virtual joystick sensor.
410 *
411 * \since This struct is available since SDL 3.2.0.
412 *
413 * \sa SDL_VirtualJoystickDesc
414 */
416{
417 SDL_SensorType type; /**< the type of this sensor */
418 float rate; /**< the update frequency of this sensor, may be 0.0f */
420
421/**
422 * The structure that describes a virtual joystick.
423 *
424 * This structure should be initialized using SDL_INIT_INTERFACE(). All
425 * elements of this structure are optional.
426 *
427 * \since This struct is available since SDL 3.2.0.
428 *
429 * \sa SDL_AttachVirtualJoystick
430 * \sa SDL_INIT_INTERFACE
431 * \sa SDL_VirtualJoystickSensorDesc
432 * \sa SDL_VirtualJoystickTouchpadDesc
433 */
435{
436 Uint32 version; /**< the version of this interface */
437 Uint16 type; /**< `SDL_JoystickType` */
438 Uint16 padding; /**< unused */
439 Uint16 vendor_id; /**< the USB vendor ID of this joystick */
440 Uint16 product_id; /**< the USB product ID of this joystick */
441 Uint16 naxes; /**< the number of axes on this joystick */
442 Uint16 nbuttons; /**< the number of buttons on this joystick */
443 Uint16 nballs; /**< the number of balls on this joystick */
444 Uint16 nhats; /**< the number of hats on this joystick */
445 Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */
446 Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */
447 Uint16 padding2[2]; /**< unused */
448 Uint32 button_mask; /**< A mask of which buttons are valid for this controller
449 e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */
450 Uint32 axis_mask; /**< A mask of which axes are valid for this controller
451 e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
452 const char *name; /**< the name of the joystick */
453 const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */
454 const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */
455
456 void *userdata; /**< User data pointer passed to callbacks */
457 void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
458 void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
459 bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
460 bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
461 bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
462 bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
463 bool (SDLCALL *SetSensorsEnabled)(void *userdata, bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
464 void (SDLCALL *Cleanup)(void *userdata); /**< Cleans up the userdata when the joystick is detached */
466
467/* Check the size of SDL_VirtualJoystickDesc
468 *
469 * If this assert fails, either the compiler is padding to an unexpected size,
470 * or the interface has been updated and this should be updated to match and
471 * the code using this interface should be updated to handle the old version.
472 */
473SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE,
474 (sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) ||
475 (sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136));
476
477/**
478 * Attach a new virtual joystick.
479 *
480 * Apps can create virtual joysticks, that exist without hardware directly
481 * backing them, and have program-supplied inputs. Once attached, a virtual
482 * joystick looks like any other joystick that SDL can access. These can be
483 * used to make other things look like joysticks, or provide pre-recorded
484 * input, etc.
485 *
486 * Once attached, the app can send joystick inputs to the new virtual joystick
487 * using SDL_SetJoystickVirtualAxis(), etc.
488 *
489 * When no longer needed, the virtual joystick can be removed by calling
490 * SDL_DetachVirtualJoystick().
491 *
492 * \param desc joystick description, initialized using SDL_INIT_INTERFACE().
493 * \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
494 * more information.
495 *
496 * \since This function is available since SDL 3.2.0.
497 *
498 * \sa SDL_DetachVirtualJoystick
499 * \sa SDL_SetJoystickVirtualAxis
500 * \sa SDL_SetJoystickVirtualButton
501 * \sa SDL_SetJoystickVirtualBall
502 * \sa SDL_SetJoystickVirtualHat
503 * \sa SDL_SetJoystickVirtualTouchpad
504 * \sa SDL_SetJoystickVirtualSensorData
505 */
506extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);
507
508/**
509 * Detach a virtual joystick.
510 *
511 * \param instance_id the joystick instance ID, previously returned from
512 * SDL_AttachVirtualJoystick().
513 * \returns true on success or false on failure; call SDL_GetError() for more
514 * information.
515 *
516 * \since This function is available since SDL 3.2.0.
517 *
518 * \sa SDL_AttachVirtualJoystick
519 */
520extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
521
522/**
523 * Query whether or not a joystick is virtual.
524 *
525 * \param instance_id the joystick instance ID.
526 * \returns true if the joystick is virtual, false otherwise.
527 *
528 * \since This function is available since SDL 3.2.0.
529 */
530extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
531
532/**
533 * Set the state of an axis on an opened virtual joystick.
534 *
535 * Please note that values set here will not be applied until the next call to
536 * SDL_UpdateJoysticks, which can either be called directly, or can be called
537 * indirectly through various other SDL APIs, including, but not limited to
538 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
539 * SDL_WaitEvent.
540 *
541 * Note that when sending trigger axes, you should scale the value to the full
542 * range of Sint16. For example, a trigger at rest would have the value of
543 * `SDL_JOYSTICK_AXIS_MIN`.
544 *
545 * \param joystick the virtual joystick on which to set state.
546 * \param axis the index of the axis on the virtual joystick to update.
547 * \param value the new value for the specified axis.
548 * \returns true on success or false on failure; call SDL_GetError() for more
549 * information.
550 *
551 * \since This function is available since SDL 3.2.0.
552 *
553 * \sa SDL_SetJoystickVirtualButton
554 * \sa SDL_SetJoystickVirtualBall
555 * \sa SDL_SetJoystickVirtualHat
556 * \sa SDL_SetJoystickVirtualTouchpad
557 * \sa SDL_SetJoystickVirtualSensorData
558 */
559extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
560
561/**
562 * Generate ball motion on an opened virtual joystick.
563 *
564 * Please note that values set here will not be applied until the next call to
565 * SDL_UpdateJoysticks, which can either be called directly, or can be called
566 * indirectly through various other SDL APIs, including, but not limited to
567 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
568 * SDL_WaitEvent.
569 *
570 * \param joystick the virtual joystick on which to set state.
571 * \param ball the index of the ball on the virtual joystick to update.
572 * \param xrel the relative motion on the X axis.
573 * \param yrel the relative motion on the Y axis.
574 * \returns true on success or false on failure; call SDL_GetError() for more
575 * information.
576 *
577 * \since This function is available since SDL 3.2.0.
578 *
579 * \sa SDL_SetJoystickVirtualAxis
580 * \sa SDL_SetJoystickVirtualButton
581 * \sa SDL_SetJoystickVirtualHat
582 * \sa SDL_SetJoystickVirtualTouchpad
583 * \sa SDL_SetJoystickVirtualSensorData
584 */
585extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
586
587/**
588 * Set the state of a button on an opened virtual joystick.
589 *
590 * Please note that values set here will not be applied until the next call to
591 * SDL_UpdateJoysticks, which can either be called directly, or can be called
592 * indirectly through various other SDL APIs, including, but not limited to
593 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
594 * SDL_WaitEvent.
595 *
596 * \param joystick the virtual joystick on which to set state.
597 * \param button the index of the button on the virtual joystick to update.
598 * \param down true if the button is pressed, false otherwise.
599 * \returns true on success or false on failure; call SDL_GetError() for more
600 * information.
601 *
602 * \since This function is available since SDL 3.2.0.
603 *
604 * \sa SDL_SetJoystickVirtualAxis
605 * \sa SDL_SetJoystickVirtualBall
606 * \sa SDL_SetJoystickVirtualHat
607 * \sa SDL_SetJoystickVirtualTouchpad
608 * \sa SDL_SetJoystickVirtualSensorData
609 */
610extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);
611
612/**
613 * Set the state of a hat on an opened virtual joystick.
614 *
615 * Please note that values set here will not be applied until the next call to
616 * SDL_UpdateJoysticks, which can either be called directly, or can be called
617 * indirectly through various other SDL APIs, including, but not limited to
618 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
619 * SDL_WaitEvent.
620 *
621 * \param joystick the virtual joystick on which to set state.
622 * \param hat the index of the hat on the virtual joystick to update.
623 * \param value the new value for the specified hat.
624 * \returns true on success or false on failure; call SDL_GetError() for more
625 * information.
626 *
627 * \since This function is available since SDL 3.2.0.
628 *
629 * \sa SDL_SetJoystickVirtualAxis
630 * \sa SDL_SetJoystickVirtualButton
631 * \sa SDL_SetJoystickVirtualBall
632 * \sa SDL_SetJoystickVirtualTouchpad
633 * \sa SDL_SetJoystickVirtualSensorData
634 */
635extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
636
637/**
638 * Set touchpad finger state on an opened virtual joystick.
639 *
640 * Please note that values set here will not be applied until the next call to
641 * SDL_UpdateJoysticks, which can either be called directly, or can be called
642 * indirectly through various other SDL APIs, including, but not limited to
643 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
644 * SDL_WaitEvent.
645 *
646 * \param joystick the virtual joystick on which to set state.
647 * \param touchpad the index of the touchpad on the virtual joystick to
648 * update.
649 * \param finger the index of the finger on the touchpad to set.
650 * \param down true if the finger is pressed, false if the finger is released.
651 * \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
652 * with the origin in the upper left.
653 * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,
654 * with the origin in the upper left.
655 * \param pressure the pressure of the finger.
656 * \returns true on success or false on failure; call SDL_GetError() for more
657 * information.
658 *
659 * \since This function is available since SDL 3.2.0.
660 *
661 * \sa SDL_SetJoystickVirtualAxis
662 * \sa SDL_SetJoystickVirtualButton
663 * \sa SDL_SetJoystickVirtualBall
664 * \sa SDL_SetJoystickVirtualHat
665 * \sa SDL_SetJoystickVirtualSensorData
666 */
667extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
668
669/**
670 * Send a sensor update for an opened virtual joystick.
671 *
672 * Please note that values set here will not be applied until the next call to
673 * SDL_UpdateJoysticks, which can either be called directly, or can be called
674 * indirectly through various other SDL APIs, including, but not limited to
675 * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
676 * SDL_WaitEvent.
677 *
678 * \param joystick the virtual joystick on which to set state.
679 * \param type the type of the sensor on the virtual joystick to update.
680 * \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with
681 * the sensor reading.
682 * \param data the data associated with the sensor reading.
683 * \param num_values the number of values pointed to by `data`.
684 * \returns true on success or false on failure; call SDL_GetError() for more
685 * information.
686 *
687 * \since This function is available since SDL 3.2.0.
688 *
689 * \sa SDL_SetJoystickVirtualAxis
690 * \sa SDL_SetJoystickVirtualButton
691 * \sa SDL_SetJoystickVirtualBall
692 * \sa SDL_SetJoystickVirtualHat
693 * \sa SDL_SetJoystickVirtualTouchpad
694 */
695extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
696
697/**
698 * Get the properties associated with a joystick.
699 *
700 * The following read-only properties are provided by SDL:
701 *
702 * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an
703 * LED that has adjustable brightness
704 * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED
705 * that has adjustable color
706 * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a
707 * player LED
708 * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has
709 * left/right rumble
710 * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has
711 * simple trigger rumble
712 *
713 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
714 * \returns a valid property ID on success or 0 on failure; call
715 * SDL_GetError() for more information.
716 *
717 * \since This function is available since SDL 3.2.0.
718 */
719extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
720
721#define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led"
722#define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led"
723#define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led"
724#define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble"
725#define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble"
726
727/**
728 * Get the implementation dependent name of a joystick.
729 *
730 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
731 * \returns the name of the selected joystick. If no name can be found, this
732 * function returns NULL; call SDL_GetError() for more information.
733 *
734 * \since This function is available since SDL 3.2.0.
735 *
736 * \sa SDL_GetJoystickNameForID
737 */
738extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
739
740/**
741 * Get the implementation dependent path of a joystick.
742 *
743 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
744 * \returns the path of the selected joystick. If no path can be found, this
745 * function returns NULL; call SDL_GetError() for more information.
746 *
747 * \since This function is available since SDL 3.2.0.
748 *
749 * \sa SDL_GetJoystickPathForID
750 */
751extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
752
753/**
754 * Get the player index of an opened joystick.
755 *
756 * For XInput controllers this returns the XInput user index. Many joysticks
757 * will not be able to supply this information.
758 *
759 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
760 * \returns the player index, or -1 if it's not available.
761 *
762 * \since This function is available since SDL 3.2.0.
763 *
764 * \sa SDL_SetJoystickPlayerIndex
765 */
766extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
767
768/**
769 * Set the player index of an opened joystick.
770 *
771 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
772 * \param player_index player index to assign to this joystick, or -1 to clear
773 * the player index and turn off player LEDs.
774 * \returns true on success or false on failure; call SDL_GetError() for more
775 * information.
776 *
777 * \since This function is available since SDL 3.2.0.
778 *
779 * \sa SDL_GetJoystickPlayerIndex
780 */
781extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
782
783/**
784 * Get the implementation-dependent GUID for the joystick.
785 *
786 * This function requires an open joystick.
787 *
788 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
789 * \returns the GUID of the given joystick. If called on an invalid index,
790 * this function returns a zero GUID; call SDL_GetError() for more
791 * information.
792 *
793 * \since This function is available since SDL 3.2.0.
794 *
795 * \sa SDL_GetJoystickGUIDForID
796 * \sa SDL_GUIDToString
797 */
798extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
799
800/**
801 * Get the USB vendor ID of an opened joystick, if available.
802 *
803 * If the vendor ID isn't available this function returns 0.
804 *
805 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
806 * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
807 *
808 * \since This function is available since SDL 3.2.0.
809 *
810 * \sa SDL_GetJoystickVendorForID
811 */
812extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
813
814/**
815 * Get the USB product ID of an opened joystick, if available.
816 *
817 * If the product ID isn't available this function returns 0.
818 *
819 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
820 * \returns the USB product ID of the selected joystick, or 0 if unavailable.
821 *
822 * \since This function is available since SDL 3.2.0.
823 *
824 * \sa SDL_GetJoystickProductForID
825 */
826extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
827
828/**
829 * Get the product version of an opened joystick, if available.
830 *
831 * If the product version isn't available this function returns 0.
832 *
833 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
834 * \returns the product version of the selected joystick, or 0 if unavailable.
835 *
836 * \since This function is available since SDL 3.2.0.
837 *
838 * \sa SDL_GetJoystickProductVersionForID
839 */
840extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
841
842/**
843 * Get the firmware version of an opened joystick, if available.
844 *
845 * If the firmware version isn't available this function returns 0.
846 *
847 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
848 * \returns the firmware version of the selected joystick, or 0 if
849 * unavailable.
850 *
851 * \since This function is available since SDL 3.2.0.
852 */
853extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
854
855/**
856 * Get the serial number of an opened joystick, if available.
857 *
858 * Returns the serial number of the joystick, or NULL if it is not available.
859 *
860 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
861 * \returns the serial number of the selected joystick, or NULL if
862 * unavailable.
863 *
864 * \since This function is available since SDL 3.2.0.
865 */
866extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
867
868/**
869 * Get the type of an opened joystick.
870 *
871 * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
872 * \returns the SDL_JoystickType of the selected joystick.
873 *
874 * \since This function is available since SDL 3.2.0.
875 *
876 * \sa SDL_GetJoystickTypeForID
877 */
878extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
879
880/**
881 * Get the device information encoded in a SDL_GUID structure.
882 *
883 * \param guid the SDL_GUID you wish to get info about.
884 * \param vendor a pointer filled in with the device VID, or 0 if not
885 * available.
886 * \param product a pointer filled in with the device PID, or 0 if not
887 * available.
888 * \param version a pointer filled in with the device version, or 0 if not
889 * available.
890 * \param crc16 a pointer filled in with a CRC used to distinguish different
891 * products with the same VID/PID, or 0 if not available.
892 *
893 * \since This function is available since SDL 3.2.0.
894 *
895 * \sa SDL_GetJoystickGUIDForID
896 */
897extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
898
899/**
900 * Get the status of a specified joystick.
901 *
902 * \param joystick the joystick to query.
903 * \returns true if the joystick has been opened, false if it has not; call
904 * SDL_GetError() for more information.
905 *
906 * \since This function is available since SDL 3.2.0.
907 */
908extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
909
910/**
911 * Get the instance ID of an opened joystick.
912 *
913 * \param joystick an SDL_Joystick structure containing joystick information.
914 * \returns the instance ID of the specified joystick on success or 0 on
915 * failure; call SDL_GetError() for more information.
916 *
917 * \since This function is available since SDL 3.2.0.
918 */
919extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
920
921/**
922 * Get the number of general axis controls on a joystick.
923 *
924 * Often, the directional pad on a game controller will either look like 4
925 * separate buttons or a POV hat, and not axes, but all of this is up to the
926 * device and platform.
927 *
928 * \param joystick an SDL_Joystick structure containing joystick information.
929 * \returns the number of axis controls/number of axes on success or -1 on
930 * failure; call SDL_GetError() for more information.
931 *
932 * \since This function is available since SDL 3.2.0.
933 *
934 * \sa SDL_GetJoystickAxis
935 * \sa SDL_GetNumJoystickBalls
936 * \sa SDL_GetNumJoystickButtons
937 * \sa SDL_GetNumJoystickHats
938 */
939extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
940
941/**
942 * Get the number of trackballs on a joystick.
943 *
944 * Joystick trackballs have only relative motion events associated with them
945 * and their state cannot be polled.
946 *
947 * Most joysticks do not have trackballs.
948 *
949 * \param joystick an SDL_Joystick structure containing joystick information.
950 * \returns the number of trackballs on success or -1 on failure; call
951 * SDL_GetError() for more information.
952 *
953 * \since This function is available since SDL 3.2.0.
954 *
955 * \sa SDL_GetJoystickBall
956 * \sa SDL_GetNumJoystickAxes
957 * \sa SDL_GetNumJoystickButtons
958 * \sa SDL_GetNumJoystickHats
959 */
960extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);
961
962/**
963 * Get the number of POV hats on a joystick.
964 *
965 * \param joystick an SDL_Joystick structure containing joystick information.
966 * \returns the number of POV hats on success or -1 on failure; call
967 * SDL_GetError() for more information.
968 *
969 * \since This function is available since SDL 3.2.0.
970 *
971 * \sa SDL_GetJoystickHat
972 * \sa SDL_GetNumJoystickAxes
973 * \sa SDL_GetNumJoystickBalls
974 * \sa SDL_GetNumJoystickButtons
975 */
976extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
977
978/**
979 * Get the number of buttons on a joystick.
980 *
981 * \param joystick an SDL_Joystick structure containing joystick information.
982 * \returns the number of buttons on success or -1 on failure; call
983 * SDL_GetError() for more information.
984 *
985 * \since This function is available since SDL 3.2.0.
986 *
987 * \sa SDL_GetJoystickButton
988 * \sa SDL_GetNumJoystickAxes
989 * \sa SDL_GetNumJoystickBalls
990 * \sa SDL_GetNumJoystickHats
991 */
992extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
993
994/**
995 * Set the state of joystick event processing.
996 *
997 * If joystick events are disabled, you must call SDL_UpdateJoysticks()
998 * yourself and check the state of the joystick when you want joystick
999 * information.
1000 *
1001 * \param enabled whether to process joystick events or not.
1002 *
1003 * \since This function is available since SDL 3.2.0.
1004 *
1005 * \sa SDL_JoystickEventsEnabled
1006 * \sa SDL_UpdateJoysticks
1007 */
1008extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled);
1009
1010/**
1011 * Query the state of joystick event processing.
1012 *
1013 * If joystick events are disabled, you must call SDL_UpdateJoysticks()
1014 * yourself and check the state of the joystick when you want joystick
1015 * information.
1016 *
1017 * \returns true if joystick events are being processed, false otherwise.
1018 *
1019 * \since This function is available since SDL 3.2.0.
1020 *
1021 * \sa SDL_SetJoystickEventsEnabled
1022 */
1023extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void);
1024
1025/**
1026 * Update the current state of the open joysticks.
1027 *
1028 * This is called automatically by the event loop if any joystick events are
1029 * enabled.
1030 *
1031 * \since This function is available since SDL 3.2.0.
1032 */
1033extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
1034
1035/**
1036 * Get the current state of an axis control on a joystick.
1037 *
1038 * SDL makes no promises about what part of the joystick any given axis refers
1039 * to. Your game should have some sort of configuration UI to let users
1040 * specify what each axis should be bound to. Alternately, SDL's higher-level
1041 * Game Controller API makes a great effort to apply order to this lower-level
1042 * interface, so you know that a specific axis is the "left thumb stick," etc.
1043 *
1044 * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
1045 * 32767) representing the current position of the axis. It may be necessary
1046 * to impose certain tolerances on these values to account for jitter.
1047 *
1048 * \param joystick an SDL_Joystick structure containing joystick information.
1049 * \param axis the axis to query; the axis indices start at index 0.
1050 * \returns a 16-bit signed integer representing the current position of the
1051 * axis or 0 on failure; call SDL_GetError() for more information.
1052 *
1053 * \since This function is available since SDL 3.2.0.
1054 *
1055 * \sa SDL_GetNumJoystickAxes
1056 */
1057extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis);
1058
1059/**
1060 * Get the initial state of an axis control on a joystick.
1061 *
1062 * The state is a value ranging from -32768 to 32767.
1063 *
1064 * The axis indices start at index 0.
1065 *
1066 * \param joystick an SDL_Joystick structure containing joystick information.
1067 * \param axis the axis to query; the axis indices start at index 0.
1068 * \param state upon return, the initial value is supplied here.
1069 * \returns true if this axis has any initial value, or false if not.
1070 *
1071 * \since This function is available since SDL 3.2.0.
1072 */
1073extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
1074
1075/**
1076 * Get the ball axis change since the last poll.
1077 *
1078 * Trackballs can only return relative motion since the last call to
1079 * SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`.
1080 *
1081 * Most joysticks do not have trackballs.
1082 *
1083 * \param joystick the SDL_Joystick to query.
1084 * \param ball the ball index to query; ball indices start at index 0.
1085 * \param dx stores the difference in the x axis position since the last poll.
1086 * \param dy stores the difference in the y axis position since the last poll.
1087 * \returns true on success or false on failure; call SDL_GetError() for more
1088 * information.
1089 *
1090 * \since This function is available since SDL 3.2.0.
1091 *
1092 * \sa SDL_GetNumJoystickBalls
1093 */
1094extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
1095
1096/**
1097 * Get the current state of a POV hat on a joystick.
1098 *
1099 * The returned value will be one of the `SDL_HAT_*` values.
1100 *
1101 * \param joystick an SDL_Joystick structure containing joystick information.
1102 * \param hat the hat index to get the state from; indices start at index 0.
1103 * \returns the current hat position.
1104 *
1105 * \since This function is available since SDL 3.2.0.
1106 *
1107 * \sa SDL_GetNumJoystickHats
1108 */
1109extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);
1110
1111#define SDL_HAT_CENTERED 0x00u
1112#define SDL_HAT_UP 0x01u
1113#define SDL_HAT_RIGHT 0x02u
1114#define SDL_HAT_DOWN 0x04u
1115#define SDL_HAT_LEFT 0x08u
1116#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
1117#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
1118#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
1119#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
1120
1121/**
1122 * Get the current state of a button on a joystick.
1123 *
1124 * \param joystick an SDL_Joystick structure containing joystick information.
1125 * \param button the button index to get the state from; indices start at
1126 * index 0.
1127 * \returns true if the button is pressed, false otherwise.
1128 *
1129 * \since This function is available since SDL 3.2.0.
1130 *
1131 * \sa SDL_GetNumJoystickButtons
1132 */
1133extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
1134
1135/**
1136 * Start a rumble effect.
1137 *
1138 * Each call to this function cancels any previous rumble effect, and calling
1139 * it with 0 intensity stops any rumbling.
1140 *
1141 * This function requires you to process SDL events or call
1142 * SDL_UpdateJoysticks() to update rumble state.
1143 *
1144 * \param joystick the joystick to vibrate.
1145 * \param low_frequency_rumble the intensity of the low frequency (left)
1146 * rumble motor, from 0 to 0xFFFF.
1147 * \param high_frequency_rumble the intensity of the high frequency (right)
1148 * rumble motor, from 0 to 0xFFFF.
1149 * \param duration_ms the duration of the rumble effect, in milliseconds.
1150 * \returns true, or false if rumble isn't supported on this joystick.
1151 *
1152 * \since This function is available since SDL 3.2.0.
1153 */
1154extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
1155
1156/**
1157 * Start a rumble effect in the joystick's triggers.
1158 *
1159 * Each call to this function cancels any previous trigger rumble effect, and
1160 * calling it with 0 intensity stops any rumbling.
1161 *
1162 * Note that this is rumbling of the _triggers_ and not the game controller as
1163 * a whole. This is currently only supported on Xbox One controllers. If you
1164 * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
1165 * instead.
1166 *
1167 * This function requires you to process SDL events or call
1168 * SDL_UpdateJoysticks() to update rumble state.
1169 *
1170 * \param joystick the joystick to vibrate.
1171 * \param left_rumble the intensity of the left trigger rumble motor, from 0
1172 * to 0xFFFF.
1173 * \param right_rumble the intensity of the right trigger rumble motor, from 0
1174 * to 0xFFFF.
1175 * \param duration_ms the duration of the rumble effect, in milliseconds.
1176 * \returns true on success or false on failure; call SDL_GetError() for more
1177 * information.
1178 *
1179 * \since This function is available since SDL 3.2.0.
1180 *
1181 * \sa SDL_RumbleJoystick
1182 */
1183extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
1184
1185/**
1186 * Update a joystick's LED color.
1187 *
1188 * An example of a joystick LED is the light on the back of a PlayStation 4's
1189 * DualShock 4 controller.
1190 *
1191 * For joysticks with a single color LED, the maximum of the RGB values will
1192 * be used as the LED brightness.
1193 *
1194 * \param joystick the joystick to update.
1195 * \param red the intensity of the red LED.
1196 * \param green the intensity of the green LED.
1197 * \param blue the intensity of the blue LED.
1198 * \returns true on success or false on failure; call SDL_GetError() for more
1199 * information.
1200 *
1201 * \since This function is available since SDL 3.2.0.
1202 */
1203extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
1204
1205/**
1206 * Send a joystick specific effect packet.
1207 *
1208 * \param joystick the joystick to affect.
1209 * \param data the data to send to the joystick.
1210 * \param size the size of the data to send to the joystick.
1211 * \returns true on success or false on failure; call SDL_GetError() for more
1212 * information.
1213 *
1214 * \since This function is available since SDL 3.2.0.
1215 */
1216extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
1217
1218/**
1219 * Close a joystick previously opened with SDL_OpenJoystick().
1220 *
1221 * \param joystick the joystick device to close.
1222 *
1223 * \since This function is available since SDL 3.2.0.
1224 *
1225 * \sa SDL_OpenJoystick
1226 */
1227extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
1228
1229/**
1230 * Get the connection state of a joystick.
1231 *
1232 * \param joystick the joystick to query.
1233 * \returns the connection state on success or
1234 * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
1235 * for more information.
1236 *
1237 * \since This function is available since SDL 3.2.0.
1238 */
1240
1241/**
1242 * Get the battery state of a joystick.
1243 *
1244 * You should never take a battery status as absolute truth. Batteries
1245 * (especially failing batteries) are delicate hardware, and the values
1246 * reported here are best estimates based on what that hardware reports. It's
1247 * not uncommon for older batteries to lose stored power much faster than it
1248 * reports, or completely drain when reporting it has 20 percent left, etc.
1249 *
1250 * \param joystick the joystick to query.
1251 * \param percent a pointer filled in with the percentage of battery life
1252 * left, between 0 and 100, or NULL to ignore. This will be
1253 * filled in with -1 we can't determine a value or there is no
1254 * battery.
1255 * \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
1256 * call SDL_GetError() for more information.
1257 *
1258 * \since This function is available since SDL 3.2.0.
1259 */
1260extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
1261
1262/* Ends C function definitions when using C++ */
1263#ifdef __cplusplus
1264}
1265#endif
1266#include <SDL3/SDL_close_code.h>
1267
1268#endif /* SDL_joystick_h_ */
bool SDL_GetJoystickButton(SDL_Joystick *joystick, int button)
SDL_JoystickType
@ SDL_JOYSTICK_TYPE_DANCE_PAD
@ SDL_JOYSTICK_TYPE_GAMEPAD
@ SDL_JOYSTICK_TYPE_COUNT
@ SDL_JOYSTICK_TYPE_ARCADE_PAD
@ SDL_JOYSTICK_TYPE_UNKNOWN
@ SDL_JOYSTICK_TYPE_ARCADE_STICK
@ SDL_JOYSTICK_TYPE_WHEEL
@ SDL_JOYSTICK_TYPE_THROTTLE
@ SDL_JOYSTICK_TYPE_GUITAR
@ SDL_JOYSTICK_TYPE_FLIGHT_STICK
@ SDL_JOYSTICK_TYPE_DRUM_KIT
void SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock)
SDL_Joystick * SDL_OpenJoystick(SDL_JoystickID instance_id)
void SDL_UpdateJoysticks(void)
bool SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
Uint32 SDL_JoystickID
bool SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure)
SDL_Joystick * SDL_GetJoystickFromID(SDL_JoystickID instance_id)
Uint16 SDL_GetJoystickVendor(SDL_Joystick *joystick)
SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent)
SDL_JoystickID * SDL_GetJoysticks(int *count)
const char * SDL_GetJoystickPathForID(SDL_JoystickID instance_id)
Uint16 SDL_GetJoystickProductForID(SDL_JoystickID instance_id)
bool SDL_JoystickConnected(SDL_Joystick *joystick)
Uint16 SDL_GetJoystickProductVersion(SDL_Joystick *joystick)
const char * SDL_GetJoystickPath(SDL_Joystick *joystick)
bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down)
SDL_JoystickID SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc)
void SDL_SetJoystickEventsEnabled(bool enabled)
SDL_JoystickID SDL_GetJoystickID(SDL_Joystick *joystick)
int SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id)
struct SDL_Joystick SDL_Joystick
bool SDL_DetachVirtualJoystick(SDL_JoystickID instance_id)
int SDL_GetNumJoystickHats(SDL_Joystick *joystick)
bool SDL_JoystickEventsEnabled(void)
SDL_GUID SDL_GetJoystickGUID(SDL_Joystick *joystick)
SDL_PropertiesID SDL_GetJoystickProperties(SDL_Joystick *joystick)
Uint16 SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id)
Uint16 SDL_GetJoystickProduct(SDL_Joystick *joystick)
SDL_JoystickType SDL_GetJoystickType(SDL_Joystick *joystick)
SDL_JoystickConnectionState SDL_GetJoystickConnectionState(SDL_Joystick *joystick)
bool SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values)
bool SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
Uint16 SDL_GetJoystickVendorForID(SDL_JoystickID instance_id)
int SDL_GetNumJoystickBalls(SDL_Joystick *joystick)
bool SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value)
bool SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms)
int SDL_GetNumJoystickButtons(SDL_Joystick *joystick)
void SDL_CloseJoystick(SDL_Joystick *joystick)
int SDL_GetNumJoystickAxes(SDL_Joystick *joystick)
void SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock)
bool SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
bool SDL_HasJoystick(void)
SDL_JoystickConnectionState
@ SDL_JOYSTICK_CONNECTION_INVALID
@ SDL_JOYSTICK_CONNECTION_UNKNOWN
@ SDL_JOYSTICK_CONNECTION_WIRELESS
@ SDL_JOYSTICK_CONNECTION_WIRED
bool SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value)
SDL_JoystickType SDL_GetJoystickTypeForID(SDL_JoystickID instance_id)
bool SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size)
bool SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel)
bool SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state)
const char * SDL_GetJoystickSerial(SDL_Joystick *joystick)
void SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16)
bool SDL_IsJoystickVirtual(SDL_JoystickID instance_id)
Uint8 SDL_GetJoystickHat(SDL_Joystick *joystick, int hat)
SDL_GUID SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id)
Uint16 SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick)
Sint16 SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis)
int SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick)
const char * SDL_GetJoystickName(SDL_Joystick *joystick)
bool SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index)
SDL_Joystick * SDL_GetJoystickFromPlayerIndex(int player_index)
const char * SDL_GetJoystickNameForID(SDL_JoystickID instance_id)
#define SDL_ACQUIRE(x)
Definition SDL_mutex.h:157
struct SDL_Mutex SDL_Mutex
Definition SDL_mutex.h:296
#define SDL_RELEASE(x)
Definition SDL_mutex.h:177
SDL_PowerState
Definition SDL_power.h:57
Uint32 SDL_PropertiesID
SDL_SensorType
Definition SDL_sensor.h:133
uint8_t Uint8
Definition SDL_stdinc.h:425
uint16_t Uint16
Definition SDL_stdinc.h:443
SDL_MALLOC size_t size
int16_t Sint16
Definition SDL_stdinc.h:434
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:209
#define bool
Definition SDL_stdinc.h:72
uint64_t Uint64
Definition SDL_stdinc.h:483
uint32_t Uint32
Definition SDL_stdinc.h:461
const SDL_VirtualJoystickTouchpadDesc * touchpads
void(* Cleanup)(void *userdata)
void(* SetPlayerIndex)(void *userdata, int player_index)
const SDL_VirtualJoystickSensorDesc * sensors
bool(* SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue)
void(* Update)(void *userdata)
bool(* RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble)
bool(* SetSensorsEnabled)(void *userdata, bool enabled)
bool(* Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
bool(* SendEffect)(void *userdata, const void *data, int size)