Keep in mind that we are still building things, so the docs could be totally wrong or incomplete.
null0
Input
🕹

The idea with input is that all is a "button" and buttons can be up or down.
All input is routed through a couple of callback-functions, so you can respond to it, easily, or drill into specific input.

See here (opens in a new tab) for info on how RetroArch maps keys to the virtual gamepad.

Here is an example, click to focus for input:

Source: input (opens in a new tab)

The null0 zip-file looks like this:

├── assets
│ ├── a.png
│ ├── b.png
│ ├── bg.png
│ ├── down.png
│ ├── l1.png
│ ├── left.png
│ ├── r1.png
│ ├── right.png
│ ├── select.png
│ ├── start.png
│ ├── up.png
│ ├── x.png
│ └── y.png
└── main.wasm

GamepadButton

This is an enum that represents the directional or button that was pressed/released.

GAMEPAD_BUTTON_UP,              // Gamepad left DPAD up button
GAMEPAD_BUTTON_RIGHT,           // Gamepad left DPAD right button
GAMEPAD_BUTTON_DOWN,            // Gamepad left DPAD down button
GAMEPAD_BUTTON_LEFT,            // Gamepad left DPAD left button
GAMEPAD_BUTTON_Y,               // Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
GAMEPAD_BUTTON_B,               // Gamepad right button right (i.e. PS3: Square, Xbox: X)
GAMEPAD_BUTTON_A,               // Gamepad right button down (i.e. PS3: Cross, Xbox: A)
GAMEPAD_BUTTON_X,               // Gamepad right button left (i.e. PS3: Circle, Xbox: B)
GAMEPAD_BUTTON_LEFT_SHOULDER,   // Gamepad top/back trigger left (first), it could be a trailing button
GAMEPAD_BUTTON_LEFT_TRIGGER,    // Gamepad top/back trigger left (second), it could be a trailing button
GAMEPAD_BUTTON_RIGHT_SHOULDER,  // Gamepad top/back trigger right (one), it could be a trailing button
GAMEPAD_BUTTON_RIGHT_TRIGGER,   // Gamepad top/back trigger right (second), it could be a trailing button
GAMEPAD_BUTTON_SELECT,          // Gamepad center buttons, left one (i.e. PS3: Select)
GAMEPAD_BUTTON_MENU,            // Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX)
GAMEPAD_BUTTON_START,           // Gamepad center buttons, right one (i.e. PS3: Start)
GAMEPAD_BUTTON_LEFT_THUMB,      // Gamepad joystick pressed button left
GAMEPAD_BUTTON_RIGHT_THUMB,     // Gamepad joystick pressed button right

buttonDown()

This is called whenever a button or directional is pressed on the virtual gamepad.

proc buttonDown(button: GamepadButton) {.null0.} =
  # handle your input here
  if button == GAMEPAD_BUTTON_A:
    echo "A pressed!"

buttonUp()

This is called whenever a button or directional is un-pressed on the virtual gamepad.

proc buttonUp(button: GamepadButton) {.null0.} =
  # handle your input here
  if button == GAMEPAD_BUTTON_A:
    echo "A released!"

no callbacks

Using the above callbacks, you can quickly get "mapped" input, which means that the up-arrow on the keyboard is the same as up on gamepad 1 or 2. If you want finer-grained control of things, you can use direct lookups of state for mouse/gamepad/keyboard.

  • You can drill into specific inputs (if you care about keyboard vs gamepad, for example)
  • You can see this header (opens in a new tab) for all the input-enums.
  • You can use pressed/released functions to trigger actions, and it will debounce and only fire once.
  • You can use down/up to get the current state of it
# has the key been pressed? (tracks unpress/read correctly)
proc key_pressed(key:Key): boolean
 
# is the key currently down?
proc key_down(key:Key): boolean
 
# is the key released? (tracks press/read correctly)
proc key_released(key:Key): boolean
 
# is the key currently up?
proc key_up(key:Key): boolean
 
# has the button been pressed? (tracks unpress/read correctly)
proc gamepad_button_pressed(gamepad:i32, key:GamepadButton): boolean
 
# is the button currently down?
proc gamepad_button_down(i32 gamepad, GamepadButton key): boolean
 
# is the button released? (tracks press/read correctly)
proc gamepad_button_released(i32 gamepad, GamepadButton key): boolean
 
# is the button currently up?
proc gamepad_button_up(i32 gamepad, GamepadButton key): boolean
 
# current position of mouse
proc mouse_position(): Vector*
 
# has the button been pressed? (tracks unpress/read correctly)
proc mouse_button_pressed(MouseButton button): boolean
 
# is the button currently down?
proc mouse_button_down(MouseButton button): boolean
 
# is the button released? (tracks press/read correctly)
proc mouse_button_released(MouseButton button): boolean
 
# is the button currently up?
proc mouse_button_up(MouseButton button): boolean