Input in Godot mostly works on the first try, and then the details catch up with you: diagonals are faster than straight lines, a gentle push on the stick does nothing, clicking a button also fires the gun, and players ask to change the keys. This article covers what Godot does between the key and your script. Every number and every behavior of the code below was run in Godot 4.7.2; the editor labels and the keyboard-layout details were checked against the 4.7 documentation and editor source.
An action is a name, a dead zone and a list of inputs
Open Project > Project Settings and select the Input Map tab. Type a name into Add New Action, click Add, then click the + button on the new row to add an event. With the event dialog open, press the key, click the mouse button or move the stick you want, and Godot fills in the event. One action can hold any number of events, from the dialog's four kinds: Keyboard Keys, Mouse Buttons, Joypad Buttons and Joypad Axes.
Each action also has a dead zone, the Deadzone column, which decides how far a stick has to move before the action counts. Godot writes your actions into the [input] section of project.godot, so actions travel with the project and show up in version control.
The scripts in this article use six actions. Create them before running any of the code:
move_left: A, and the left stick pushed leftmove_right: D, and the left stick pushed rightmove_up: W, and the left stick pushed upmove_down: S, and the left stick pushed downdash: Shift, and the bottom face button (A on Xbox, Cross on PlayStation)interact: E, and the left face button (X on Xbox, Square on PlayStation)
Scripts refer to actions by name, and a misspelled name does not stop the game. Input.is_action_pressed("move_lft") returns false and Godot reports The InputMap action "move_lft" doesn't exist. Did you mean "move_left"? every time the line runs. The suggestion only appears when Godot finds a close enough name ("dahs" gets none), so if a control silently does nothing, look for this error first.
Held, pressed once, or an event: three ways to read an action
Godot answers three different questions about an action, and each one suits a different kind of control:
- What is held right now?
Input.is_action_pressed(),Input.get_axis()andInput.get_vector(). Ask every physics tick for anything continuous: walking, steering, holding a shield. - Did it start or stop this tick?
Input.is_action_just_pressed()andInput.is_action_just_released(). They are true for one physics tick when you call them in_physics_process()and for one frame in_process(), and a tap that starts and ends within a single frame still counts once. Use them for a dash or a jump decided inside physics code. - Did an event arrive?
_unhandled_input(event)withevent.is_action_pressed()runs once, when the press happens. When a held key starts repeating, its repeat events do not count:is_action_pressed()ignores them unless you passtrueas its second argument. Use it for presses that have nothing to do with the physics step, such as interact, pause or opening the inventory.
This script uses all three. Attach it to a CharacterBody2D with a CollisionShape2D, and set the body's Motion Mode to Floating in the Inspector, the mode for top-down movement with no floor.
extends CharacterBody2D
signal interacted
const SPEED := 200.0
const DASH_SPEED := 700.0
const ACCELERATION := 2000.0
func _physics_process(delta: float) -> void:
var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
if Input.is_action_just_pressed("dash") and direction != Vector2.ZERO:
velocity = direction.normalized() * DASH_SPEED
velocity = velocity.move_toward(direction * SPEED, ACCELERATION * delta)
move_and_slide()
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("interact"):
interacted.emit()Walking is polled every tick. The dash sets the velocity once, on the tick Shift goes down, and move_toward() brings it back to walking speed in about a quarter of a second; holding Shift does not dash again. Interact arrives as an event and the script only announces it: the door or the shopkeeper the player is standing next to connects to the signal and decides what happens.
Reading a press on exactly one tick has a cost in a platformer: a jump pressed three frames before landing finds is_on_floor() false and is lost. The 2D platformer tutorial keeps the press for a short window instead, which is called jump buffering.
The event dialog offers only those four kinds of event, so anything else, mouse movement included, has to be read from the event itself. For mouse look, read InputEventMouseMotion in _unhandled_input() and use its screen_relative, which unlike relative is not scaled by the project's stretch settings. The free FPS controller reads it this way.
What Input.get_vector actually returns
Input.get_vector() takes four action names in the order negative x, positive x, negative y, positive y. In 2D, y grows downwards, so up is the third name and down the fourth. In 3D, pass the forward action third and use the result's y as the z of the movement, as the first 3D scene tutorial does.
The vector it returns is capped at a length of 1, not normalized. Here is what it returned in Godot 4.7.2 for the actions above, with their default 0.2 dead zone:
- D and S held together:
(0.71, 0.71), a length of 1. TwoInput.get_axis()calls give(1, 1)for the same keys, which moves the player 41% faster on diagonals. - Left stick halfway to the right, at 0.5:
(0.375, 0). - Left stick almost fully diagonal, at (0.7, 0.7):
(0.698, 0.698), a length of 0.99. - Left stick resting at 0.1:
(0, 0).
A half-tilted stick therefore walks at 37.5% of full speed, which is analog walking without any extra code. Calling normalized() on the result throws that away and turns every tilt into full speed, which is why the player script above normalizes only the dash direction. The next section explains why half a tilt gives 0.375 and not 0.5.
Dead zones decide how much a gentle push counts
Below its dead zone an action is not pressed at all. Above it, Godot rescales the input so its strength runs from 0 at the dead zone to 1 at full tilt: strength = (value − dead zone) / (1 − dead zone). With the default 0.2, a stick at 0.25 gives a strength of 0.0625, 0.5 gives 0.375 and 0.6 gives 0.5. Input.get_action_raw_strength() returns the value before that rescaling.
Actions you add yourself start at 0.2, both in the Input Map tab and with InputMap.add_action(). The built-in ui_ actions that menus use start at 0.5, so a stick that steers the player can still be too light to move between menu buttons.
get_vector() applies its dead zone to the length of the whole stick rather than to each axis. By default it uses the average of its four actions' dead zones, and a fifth argument overrides that: Input.get_vector("move_left", "move_right", "move_up", "move_down", 0.3). Because the zone is a circle, a stick resting at (0.15, 0.15) gives a small vector of (0.011, 0.011) even though Input.get_axis() returns 0 on both axes: the length, 0.21, is just outside 0.2.
So if a worn controller makes the character creep, raise the dead zone of the movement actions. If light pushes are ignored, lower it. A sensitivity option in your settings can call InputMap.action_set_deadzone() while the game runs.
WASD on a French keyboard: physical keys and key labels
An AZERTY keyboard has Z and Q where QWERTY has W and A. If movement were bound to the letter W, a French player would have to use keys scattered across the keyboard. The event dialog avoids that with its key mode setting, which has three options:
- Physical Keycode (Position on US QWERTY Keyboard): the key in that position, whatever is printed on it. This is the default for new events, so WASD bound in the editor already becomes ZQSD on a French keyboard.
- Keycode (Latin Equivalent): the letter. Godot's documentation recommends it for shortcuts, such as Ctrl+S for saving.
- Key Label (Unicode, Case-Insensitive): the character printed on the key, meant for key prompts.
Physical keys leave one problem: the prompt. "Press W to move up" is wrong on a French keyboard, where that key says Z. DisplayServer.keyboard_get_label_from_physical() converts a position into the label on the player's current layout, and the prompt_for() function in the rebinding section below uses it for exactly that.
A click on a button should not fire the gun
Godot sends each input event through the scene in a fixed order: _input() first, then the GUI, then _shortcut_input() and _unhandled_key_input(), and finally _unhandled_input(). A Control that uses an event stops it there, so _unhandled_input() never sees a click that pressed a button. Polling does not follow that order. With interact also bound to the left mouse button, a click on a Button in Godot 4.7.2 pressed the button and made Input.is_action_just_pressed("interact") true on the same tick, while the _unhandled_input() in the player script stayed quiet. Read any action that shares a key or button with your UI from _unhandled_input().
The second trap is focus. A Button you click keeps keyboard focus, because a Button's focus mode is All by default. Space and Enter belong to the built-in ui_accept action, so the next Space press presses that button again. If your jump is on Space, click Restart, then jump, and the level restarts as the player leaves the ground. Set Focus > Mode to None in the Inspector for buttons the player clicks during play. Menu buttons that a controller has to move between need focus, so leave those alone.
Let players rebind a key and keep it after a restart
InputMap can be changed while the game runs, but only in memory: the next launch starts from project.godot again. A rebinding screen needs three things: catch the next key, replace the old key in the action, and save the result in user://, the per-user folder the save system tutorial explains.
Save this as input_settings.gd. It is not attached to a node: class_name makes its static functions available from any script as InputSettings.save() and so on.
class_name InputSettings
const PATH := "user://input.cfg"
const REBINDABLE: Array[StringName] = [&"move_left", &"move_right", &"move_up", &"move_down", &"dash", &"interact"]
static func rebind(action: StringName, event: InputEvent) -> void:
for old in InputMap.action_get_events(action):
if old is InputEventKey or old is InputEventMouseButton:
InputMap.action_erase_event(action, old)
var binding: InputEvent = event.duplicate()
binding.device = -1
if binding is InputEventKey:
binding.keycode = KEY_NONE
InputMap.action_add_event(action, binding)
save()
bindings_changed()
static func save() -> void:
var config := ConfigFile.new()
for action in REBINDABLE:
config.set_value("input", action, InputMap.action_get_events(action))
config.save(PATH)
static func load_saved() -> void:
var config := ConfigFile.new()
if config.load(PATH) != OK:
return
for action in REBINDABLE:
var events: Variant = config.get_value("input", action, null)
if events is Array and InputMap.has_action(action):
InputMap.action_erase_events(action)
for event in events:
if event is InputEvent:
InputMap.action_add_event(action, event)
bindings_changed()
static func reset() -> void:
InputMap.load_from_project_settings()
DirAccess.remove_absolute(PATH)
bindings_changed()
static func bindings_changed() -> void:
(Engine.get_main_loop() as SceneTree).call_group(&"input_bindings", &"rebuild_actions")
static func prompt_for(action: StringName) -> String:
for event in InputMap.action_get_events(action):
if event is InputEventKey:
if event.physical_keycode != KEY_NONE:
return OS.get_keycode_string(DisplayServer.keyboard_get_label_from_physical(event.physical_keycode))
return OS.get_keycode_string(event.keycode)
if event is InputEventMouseButton:
return event.as_text()
return "Unbound"rebind() removes only keyboard and mouse events, so the controller button bound to the same action survives. The copy it adds gets device -1, which means all devices, as events made in the Input Map do. Clearing keycode binds the key by position: when an event has both a keycode and a physical keycode, Godot compares the keycode first. ConfigFile stores each event in the same text format project.godot uses. reset() reloads the project's own bindings and deletes the file. After each change, bindings_changed() calls rebuild_actions() on every node in the input_bindings group, for scripts that build actions of their own from these; the two-player script at the end of this article is one.
Load the saved keys before any node reads them, which means from an autoload. A scene's root runs _ready() after all of its children, so a rebind button or a player in your first scene would already have read the old keys. Save this as input_boot.gd and add it in Project Settings > Globals > Autoload; autoloads are ready before the main scene is loaded:
extends Node
func _ready() -> void:
InputSettings.load_saved()Attach the next script to a Button in your options menu, one per action, and set its Action in the Inspector:
extends Button
@export var action: StringName = &"dash"
var listening := false
func _ready() -> void:
pressed.connect(_on_pressed)
text = InputSettings.prompt_for(action)
func _on_pressed() -> void:
listening = true
text = "Press a key..."
func _input(event: InputEvent) -> void:
if not listening or not event.is_pressed() or event.is_echo():
return
if not (event is InputEventKey or event is InputEventMouseButton):
return
get_viewport().set_input_as_handled()
listening = false
if not event.is_action("ui_cancel"):
InputSettings.rebind(action, event)
text = InputSettings.prompt_for(action)The button listens in _input(), which runs before the GUI, and marks the event as handled so the key being assigned does not also press a button or reach the game. Escape, the built-in ui_cancel, cancels and keeps the old key. A Button reports pressed when the mouse is released, so the click that started listening is not captured; the next click is, and binds that mouse button.
Two controllers, two players
Events you add in the Input Map use All Devices, so every action answers every controller. For one player that is right. For two players on one screen it is not: both sticks would move both characters, and polling cannot tell which controller a value came from. Instead, give each player their own actions whose controller events name one device. Controllers are numbered from 0, and Input.get_connected_joypads() lists the numbers in use.
extends Node
const BASE_ACTIONS: Array[StringName] = [&"move_left", &"move_right", &"move_up", &"move_down", &"dash", &"interact"]
func _ready() -> void:
add_to_group(&"input_bindings")
rebuild_actions()
Input.joy_connection_changed.connect(_on_joy_connection_changed)
func rebuild_actions() -> void:
add_player_actions("p1_", 0, true)
add_player_actions("p2_", 1, false)
func add_player_actions(prefix: String, device: int, keyboard: bool) -> void:
for base in BASE_ACTIONS:
var action := StringName(prefix + base)
if InputMap.has_action(action):
InputMap.erase_action(action)
InputMap.add_action(action, InputMap.action_get_deadzone(base))
for event in InputMap.action_get_events(base):
if event is InputEventJoypadButton or event is InputEventJoypadMotion:
var copy: InputEvent = event.duplicate()
copy.device = device
InputMap.action_add_event(action, copy)
elif keyboard:
InputMap.action_add_event(action, event)
func _on_joy_connection_changed(device: int, connected: bool) -> void:
if not connected and device <= 1:
get_tree().paused = trueAttach it to a node in your main scene. It copies each action into a p1_ and a p2_ version with the same dead zone, points the controller events at controller 0 or 1, and gives the keyboard to player 1 only. The original actions still answer every controller, which suits menus. The copies are made from the bindings as they are at that moment, so the script joins the input_bindings group and rebuilds them after a rebind, and after reset(), whose reload removes every action added in code. In the player script, add @export var prefix := "", put prefix + in front of each action name, and set Prefix to p1_ and p2_ on the two players.
When either controller disconnects, the script pauses the game. Your pause menu needs its Process Mode set to When Paused to keep working while everything else stops, and it resumes with get_tree().paused = false.
One naming detail matters for prompts: Godot names controller buttons by position. JOY_BUTTON_A is the bottom face button, labeled A on Xbox, Cross on PlayStation and B on Nintendo controllers, and the event dialog lists all three names. Input.get_joy_name() tells you which controller a device number belongs to, if your prompts need to match it.
Verification notes
Sources and revision context
Tested in Godot 4.7.2. 55 assertions passed across 5 scripts from this article, run headless.
Godot 4.7 · Input, InputMap, InputEventKey and ConfigFile behavior run in Godot 4.7.2; the editor dialog names and the key-label conversion, which needs a desktop display, checked against the 4.7 documentation and editor source.
Published November 25, 2026. The five scripts run in Godot 4.7.2 against the six actions listed in the first section, and the get_vector and dead zone values were read from the same run. DisplayServer.keyboard_get_label_from_physical() needs a desktop display, so the AZERTY prompt is checked against the documentation only.
- Input examples Godot Engine documentation
- Using InputEvent Godot Engine documentation
- Controllers, gamepads, and joysticks Godot Engine documentation
- Input class reference Godot Engine documentation
- InputMap class reference Godot Engine documentation
- InputEventKey class reference Godot Engine documentation
- InputEventMouseMotion class reference Godot Engine documentation
- ConfigFile class reference Godot Engine documentation
