Input
Inherits: Object
Description
A singleton for handling inputs. The Input singleton handles key presses, mouse buttons and movement, gamepads, and input actions.
Properties
Controls the mouse mode (visible, hidden, captured, confined).
Methods
is_action_pressed
bool is_action_pressed(action: StringName, exact_match: bool = false)
Returns true if you are pressing the action event.
is_action_just_pressed
bool is_action_just_pressed(action: StringName, exact_match: bool = false)
Returns true when the user has started pressing the action event in the current frame.
is_key_pressed
bool is_key_pressed(keycode: Key)
Returns true if you are pressing the Latin key in the current keyboard layout.
get_vector
Vector2 get_vector(negative_x: StringName, positive_x: StringName, negative_y: StringName, positive_y: StringName, deadzone: float = -1.0)
Gets an input vector by specifying four actions for the positive and negative X and Y axes.
get_axis
float get_axis(negative_action: StringName, positive_action: StringName)
Get axis input by specifying two actions, one negative and one positive.
bool is_mouse_button_pressed(button: MouseButton)
Returns true if you are pressing the mouse button.
Example Usage
# Check if action is pressed
if Input.is_action_pressed("ui_right"):
position.x += speed * delta
# Get movement vector
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = direction * speed
# Check specific key
if Input.is_key_pressed(KEY_SPACE):
jump()
# Get axis input
var horizontal = Input.get_axis("move_left", "move_right")
// Check if action is pressed
if (Input.IsActionPressed("ui_right"))
{
position.X += speed * delta;
}
// Get movement vector
var direction = Input.GetVector("move_left", "move_right", "move_up", "move_down");
velocity = direction * speed;