1.74 class gamepad

A gamepad is the input_device of a game controller. Gamepads are enabled by display<-gamepads, which also returns the connected gamepads. The buttons and axes of a gamepad generate events for the window with the keyboard focus, as keys do:

gamepad_button_down, gamepad_button_up
A button is pressed or released.
gamepad_axis
A stick or trigger moved.

These events are event->is_a. Their event<-detail is a gamepad_input, so event<-control gives the name of the button or axis and event<-value its value. Gamepad events are only generated while the application has the keyboard focus. When a gamepad is connected or disconnected, the window with the keyboard focus of each frame receives a device_added or device_removed event.

The buttons and axes are named after their position rather than their label, so the names are the same for controllers of different brands:

For example:

event(W, Ev:event) :->
    (   send(Ev, is_a, gamepad_button_down),
        get(Ev, control, south)
    ->  send(W, fire)
    ;   send_super(W, event, Ev)
    ).
See also
- display<-gamepads
- class gamepad_input
- class input_device

1.74.1 Send methods

gamepad ->initialise: kind={mouse,pen,touch,gamepad,keyboard}, id=[int], name=[name]
Gamepads are created by xpce.
gamepad ->rumble: low=
0.0..1.0, high=0.0..1.0, milliseconds=int Rumble the low and high frequency motors with the given strength for the given time. Fails if the gamepad cannot rumble.
gamepad ->rumble_triggers: left=
0.0..1.0, right=0.0..1.0, milliseconds=int As gamepad->rumble, for the motors in the triggers.
gamepad ->led: colour
Set the colour of the LED. Fails if the gamepad has no LED.

1.74.2 Get methods

gamepad <-connected: -> bool
@off if the gamepad was disconnected.
gamepad <-button: name -> bool
@on if the named button is down.
gamepad <-axis: name -> num
The position of the named axis.
gamepad <-type: -> name
The type of the controller, e.g., xbox360, ps5, or unknown.
gamepad <-player_index: -> int
The player index of the gamepad. Fails if it has none.