# How to remap input actions in code in Godot 4: InputMap and keycode

Make an InputEventKey with physical_keycode set, then InputMap.action_erase_events("jump") and InputMap.action_add_event("jump", event). Godot 3's scancode property is gone: event.scancode = KEY_W stops with Invalid assignment of property or key 'scancode' with value of type 'int' on a base object of type 'InputEventKey'.

Source: https://flockbay.com/godot/how-to-remap-input-in-code-in-godot-4/ · Updated 2026-10-30

## What Godot is checking

Godot 4 splits a key into keycode, the character the keyboard layout produces, and physical_keycode, the key's position on a US QWERTY board. Bind movement to physical_keycode so WASD stays in the same place on AZERTY keyboards.

InputMap changes apply at once and last until the game quits. Save the player's bindings yourself, for example as keycodes in a ConfigFile, and re-apply them at startup.

## Reproduce it

A Godot 3 key event, in a Godot 4 project.

```
extends Node

func _ready() -> void:
	var event := InputEventKey.new()
	event.scancode = KEY_W
	print("after")

```

## What Godot 4.7.2 prints

```
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Invalid assignment of property or key 'scancode' with value of type 'int' on a base object of type 'InputEventKey'.
   at: _ready (res://answers/how-to-remap-input-in-code-in-godot-4/repro.gd:5)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/how-to-remap-input-in-code-in-godot-4/repro.gd:5)
```

## Fix it

Create a jump action, bind it to the physical W key, then rebind it to Space.

```
extends Node

func bind(action: StringName, key: Key) -> void:
	var event := InputEventKey.new()
	event.physical_keycode = key
	InputMap.action_erase_events(action)
	InputMap.action_add_event(action, event)

func _ready() -> void:
	InputMap.add_action("jump")
	bind("jump", KEY_W)
	print(InputMap.action_get_events("jump")[0].as_text_physical_keycode())
	bind("jump", KEY_SPACE)
	print(InputMap.action_get_events("jump")[0].as_text_physical_keycode())

```

## What the fixed script prints

```
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

W
Space
```

## Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

```
How to remap input actions in code in Godot 4: InputMap and keycode Make an InputEventKey with physical_keycode set, then InputMap.action_erase_events("jump") and InputMap.action_add_event("jump", event). Godot 3's scancode property is gone: event.scancode = KEY_W stops with Invalid assignment of property or key 'scancode' with value of type 'int' on a base object of type 'InputEventKey'. Where this calls for a change in my Godot 4 project, make it, then run the game headless and check Godot's output for errors.
```

## Verified on Godot 4.7.2

Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: [gdscript_vm.cpp line 1235, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1235), [InputMap in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/InputMap.xml).

## Questions

### How do I wait for the player to press the new key?

In _input(event), take the first InputEventKey with event.pressed and pass its physical_keycode to your bind function, then stop listening.

### How do I get the name of a key?

OS.get_keycode_string(KEY_W) returns "W"; Godot 3's OS.get_scancode_string() was renamed.

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [How to set the window size in Godot 4: get_window().size](/godot/how-to-set-the-window-size-in-godot-4/), [How to save and load a game in Godot 4: FileAccess](/godot/how-to-save-a-game-in-godot-4/), [How to connect signals in code in Godot 4: signal.connect(callable)](/godot/how-to-connect-signals-in-code-in-godot-4/), [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-node2d/), [Every verified Godot 4 answer](/godot/), [How do I connect Claude Code to Godot?](/docs/how-do-i-connect-claude-code-to-godot/)
