XDPXI's Documentation
SDL2

Input Handling

Required version: Sponge >=1.0.6

sdl2.get_input_pressed(key)

Returns true only on the frame that a key is first pressed down. Useful for detecting single key presses like button clicks.

Parameters:

  • key (string) - Key name to check

Returns: boolean - true on the frame the key is pressed, false otherwise

Supported Keys:

  • Letters: "a" through "z"
  • Numbers: "0" through "9"
  • Special: "space", "return", "escape", "backspace", "tab"
  • Arrows: "up", "down", "left", "right"
  • Modifiers: "lshift", "rshift", "lctrl", "rctrl", "lalt", "ralt"

Example:

if sdl2.get_input_pressed("space") {
    print("Space pressed!");
}

sdl2.get_input_released(key)

Returns true only on the frame that a key is released. Useful for detecting when the player stops holding a key.

Parameters:

  • key (string) - Key name to check

Returns: boolean - true on the frame the key is released, false otherwise

Example:

if sdl2.get_input_released("escape") {
    print("Escape released!");
}

sdl2.get_input_held(key)

Returns true every frame that a key is held down. Useful for continuous movement or actions.

Parameters:

  • key (string) - Key name to check

Returns: boolean - true while the key is held, false otherwise

Example:

if sdl2.get_input_held("w") {
    player_y = player_y - speed * dt;
}