18 Joysticks
This section covers low-level joystick access. For a higher-level API with standardized button names, see Gamepads.
18.1 Detection
procedure
procedure
procedure
18.2 Opening and Closing
procedure
(open-joystick instance-id) → joystick?
instance-id : exact-nonnegative-integer?
The joystick is registered with the current custodian for automatic cleanup.
procedure
(joystick-connected? joy) → boolean?
joy : joystick?
procedure
(joystick-destroy! joy) → void?
joy : joystick?
Note: Joysticks are automatically closed when their custodian shuts down.
18.3 Joystick Information
procedure
(joystick-name joy) → (or/c string? #f)
joy : joystick?
procedure
(joystick-path joy) → (or/c string? #f)
joy : joystick?
procedure
joy : joystick?
procedure
(joystick-type joy) → symbol?
joy : joystick?
Values: 'unknown, 'gamepad, 'wheel, 'arcade-stick, 'flight-stick, 'dance-pad, 'guitar, 'drum-kit, 'arcade-pad, 'throttle.
procedure
joy : joystick?
procedure
joy : joystick?
procedure
(joystick-serial joy) → (or/c string? #f)
joy : joystick?
18.3.1 Info by ID (before opening)
procedure
(get-joystick-name-for-id instance-id) → (or/c string? #f)
instance-id : exact-nonnegative-integer?
procedure
(get-joystick-type-for-id instance-id) → symbol?
instance-id : exact-nonnegative-integer?
18.4 Capabilities
procedure
joy : joystick?
procedure
joy : joystick?
procedure
joy : joystick?
procedure
joy : joystick?
18.5 Reading State
procedure
(joystick-axis joy axis-index) → exact-integer?
joy : joystick? axis-index : exact-nonnegative-integer?
procedure
(joystick-button joy button-index) → boolean?
joy : joystick? button-index : exact-nonnegative-integer?
procedure
(joystick-hat joy hat-index) → symbol?
joy : joystick? hat-index : exact-nonnegative-integer?
Values: 'centered, 'up, 'down, 'left, 'right, 'up-right, 'up-left, 'down-right, 'down-left.
procedure
(joystick-ball joy ball-index) →
exact-integer? exact-integer? joy : joystick? ball-index : exact-nonnegative-integer?
Returns (values dx dy).
18.6 Hat Value Conversion
procedure
(hat-value->symbol v) → symbol?
v : exact-nonnegative-integer?
procedure
(hat-value->list v) → (listof symbol?)
v : exact-nonnegative-integer?
For compound directions (like up-right), returns '(up right).
18.7 Player Index
procedure
(joystick-player-index joy) → exact-integer?
joy : joystick?
procedure
(set-joystick-player-index! joy index) → void?
joy : joystick? index : exact-integer?
18.8 Rumble
procedure
(joystick-rumble! joy low high [duration-ms]) → boolean?
joy : joystick? low : exact-nonnegative-integer? high : exact-nonnegative-integer? duration-ms : exact-nonnegative-integer? = 0
low and high are motor intensities (0-65535). duration-ms is the duration in milliseconds (0 = infinite).
procedure
(joystick-rumble-triggers! joy left right [ duration-ms]) → boolean? joy : joystick? left : exact-nonnegative-integer? right : exact-nonnegative-integer? duration-ms : exact-nonnegative-integer? = 0
18.9 LED
18.10 Power
procedure
(joystick-power-info joy) →
symbol? exact-integer? joy : joystick?
Power states: 'unknown, 'on-battery, 'no-battery, 'charging, 'charged, 'error.
Percentage is 0-100, or -1 if unknown.
procedure
(joystick-connection-state joy) → symbol?
joy : joystick?
Values: 'unknown, 'wired, 'wireless, 'invalid.
18.11 Type Conversion
procedure
(joystick-type->symbol type) → symbol?
type : exact-nonnegative-integer?