【Godot】Key Binding Management with InputMap

Created: 2025-06-20Last updated: 2025-12-06

A system to abstract and manage keyboard and gamepad inputs. Supporting multiple key assignments and key configuration

Overview

When playing games, many players want to customize their keyboard or gamepad button layout (key bindings) to their preferences. Godot provides the "InputMap" - a powerful feature for managing these key bindings very easily and efficiently.

This article explains the basic usage of InputMap and how it makes game development more comfortable.

What is InputMap?

InputMap is a system for centrally managing which physical keys or buttons are assigned to specific actions (e.g., "jump," "attack," "move right"). Instead of writing "when the W key is pressed" directly in code, you can handle inputs abstractly as "when the move_forward action is executed."

Benefits of Using InputMap:

  • Flexibility: Players can freely reconfigure keys in-game
  • Maintainability: Change key assignments without modifying code
  • Multi-device Support: Easily assign multiple input devices (keyboard, mouse, gamepad) to the same action

How to Configure InputMap

InputMap configuration is done from the "Project" menu in the Godot editor.

  1. Open Project Settings: Select "Project" → "Project Settings" from the menu bar
  2. Navigate to InputMap Tab: Select "InputMap" from the tabs at the top
Input Map Settings Screen
  1. Add an Action: Enter a new action name (e.g., attack) in the "Action" input field at the top and press the "Add" button

  2. Assign Events: Click the "+" icon on the right side of the added action and select "Key" or "Mouse Button." When the dialog appears, just press the physical key you want to assign to complete registration.

For example, you can assign both left mouse click and spacebar to the "attack" action.

Using from Scripts

Actions set up in InputMap can be easily called through the Input singleton. You can use methods like is_action_pressed() explained in the previous article directly.

func _process(delta):
    # Call attack processing when "attack" action is pressed
    if Input.is_action_just_pressed("attack"):
        execute_attack()

    # Get movement direction from "move_right" and "move_left"
    var direction = Input.get_axis("move_left", "move_right")
    velocity.x = direction * SPEED

Notice that the code never touches specific keys like KEY_SPACE. This means if you later want to change the attack key to Enter, you don't need to change a single line of script - just modify the InputMap settings.

Summary

InputMap is an absolutely essential feature for handling inputs in Godot. By avoiding hardcoding (writing keys directly in scripts) and adding an abstract layer called actions, your game becomes significantly more flexible and user-friendly.

When starting game development, begin by defining basic actions (move_left, move_right, jump, attack, etc.) in InputMap. This small effort will greatly improve your development efficiency later on.