How input works in Godot

InputEvent is a built-in datatype that contain different types of input events (which ones can be configured?).

Use InputMap to define a list of possible actions.

Input goes through a series of input handlers, until it’s “consumed” or it reaches the last possible handler. First it tries to act as a window manager, then sends input to the embedded focused window, if any, and then sends input to the hierarchy of handlers, starting with Node._input() and continues further on as on the image below.

When sending input to the descendant nodes, viewport will do so in depth-first order. Exception isControl._gui_input().

Implementing input

Two types of inputs: Event When we want to do respond to an input event (e.g. jump) - event is used with an _input() function.

func _input(event):
	if event.is_action_pressed("jump"):
		jump()

Polling When we want to do something as long as a key is pressed (e.g. movement) - Input singleton is used to query the state of an input.

func _physics_process(delta):
	if Input.is_action_pressed("move_right"):
		# 123
		position.x += speed * delta