← Back to Documentation

Input API

⚠️ Experimental - Pre-Release

The Input API provides methods for handling keyboard, mouse, and gamepad input. Use these methods to detect key presses, mouse clicks, and input actions.

Actions

Input.get_action(action_name: string)bool

Returns true if the specified input action is currently pressed.

if Input.get_action("jump") {    // Jump action is pressed}

Keyboard

Input.is_key_pressed(key: string) → bool / Input.get_key_pressed(key: string) → bool

Returns true if the specified key is currently pressed.

if Input.is_key_pressed("Space") {
    // Space key is pressed
}
if Input.get_key_pressed("W") {
    // W key is pressed
}

Input.get_text_input()string

Returns the current text input buffer.

Input.clear_text_input()

Clears the text input buffer.

Mouse

Input.is_button_pressed(button: int)bool / Input.is_mouse_button_pressed(button: int)bool

Returns true if the specified mouse button is currently pressed. Button 0 = left, 1 = right, 2 = middle.

if Input.is_button_pressed(0) {    // Left mouse button is pressed}

Input.get_mouse_position() → Vector2 / Input.get_mouse_pos() → Vector2

Returns the current mouse position in screen coordinates as a Vector2.

var mouse_pos = Input.get_mouse_position()Console.print("Mouse: " + mouse_pos.x + ", " + mouse_pos.y)

Input.get_mouse_position_world()Vector2 / Input.get_mouse_pos_world()Vector2

Returns the current mouse position in world coordinates as a Vector2.

Input.get_scroll_delta()float / Input.get_scroll()float

Returns the mouse wheel scroll delta.

Input.is_wheel_up()bool

Returns true if the mouse wheel is scrolling up.

Input.is_wheel_down()bool

Returns true if the mouse wheel is scrolling down.

Input.screen_to_world(screen_pos: Vector2)Vector2

Converts a screen position (Vector2) to world coordinates, returning a Vector2.

Usage Example

@script Player extends Sprite2D    var speed = 100.0     fn update() {        var delta = Time.get_delta()         // Keyboard movement        if Input.is_key_pressed("W") {            self.transform.position.y -= speed * delta        }        if Input.is_key_pressed("S") {            self.transform.position.y += speed * delta        }        if Input.is_key_pressed("A") {            self.transform.position.x -= speed * delta        }        if Input.is_key_pressed("D") {            self.transform.position.x += speed * delta        }         // Mouse click        if Input.is_button_pressed(0) {            var mouse_world = Input.get_mouse_position_world()            self.transform.position = mouse_world        }    }