Play Game Design · Godot Basics · 4 of 10

Input: keys & controllers

Make your game react to the player. You'll set up named actions like “move_left” once, so they work with any key or controller, then use them to drive your Godot logo around the screen.

⏱ About 20 minutes✅ Needs Basics 3🎮 Controller optional
0 of 4 complete
1

Feel it: pressed vs. just pressed

Godot can ask two different questions about a button: “Is it held down right now?” and “Was it pressed this exact frame?” Watch both answers over time.

Click here, then use the Space barOr use the big button below on a phone
Mission
    2

    Name it

    The words you'll see in Godot.

    Action

    A name for what the player wants to do

    Like jump or move_left. Your code asks about actions, never about specific keys.

    Event

    The real button behind an action

    The A key, the ← arrow, a controller's left stick. One action can have many events, so A and ← can both mean move_left.

    Input Map

    Where actions meet events

    A tab in Project Settings that lists every action and its events. Changing controls later means editing this list, not your code.

    pressed · just_pressed · just_released

    Three questions you can ask

    is_action_pressed is true every frame while held (good for running). is_action_just_pressed is true for one frame when pressed (good for jumping). is_action_just_released is true for one frame when let go.

    Shortcut for movement: Input.get_vector("move_left", "move_right", "move_up", "move_down") combines four actions into one direction, like (1, 0) for right or (0, -1) for up. Diagonals come out the same speed as straight lines.
    3

    Prove it: set up the Input Map

    This works just like Godot's Input Map. Practice here, and the real one will feel familiar.

    Add New Action
    ActionEvents

    Click + on an action's row, then press the key you want for it. Each + adds one key, so click it again for a second key. Action names use lowercase and underscores, exactly like they'll appear in code.

    Click to test your controlsMove with your keys · Space to spin
    Goals
      4

      Build it in Godot: drive your logo

      About 12 minutes. Open your project from Basics 3.

      1. Open Project Settings. In the menu bar at the very top left, click Project, then Project Settings…. A big window opens.
      2. Find the Input Map. Along the top of that window are tabs: General, Input Map and more. Click Input Map.Not a setting inside General: it's its own tab. The list may look empty. Godot's built-in actions (like ui_accept from the project milestones) are hidden until you tick “Show Built-in Actions,” and you can leave that off.
      3. Add your first action. At the top of the Input Map tab there's a text box labelled Add New Action. Type move_left and click + Add. It appears in the list below.
      4. Give it its first key. On the move_left row, at the far right, click the + icon (Add Event). A window called Event Configuration opens. The box at the top says it's listening for input. Press A on your keyboard. The box now shows A (Physical). Click OK.“Physical” is normal and what you want. It means Godot remembers the key's position on the keyboard, so your controls work on keyboards with other layouts too. Leave the other options in that window as they are.
      5. Add a second key. Each + adds one key. Click the same + on the move_left row again, press the ← left arrow, and click OK.Can't see your keys? Click the small ▸ arrow to the left of move_left to expand it. You should see A (Physical) and Left (Physical) listed underneath. Have a controller plugged in? Click + once more and push the left stick left while the window is listening.
      6. Add the rest the same way: type each name in Add New Action, click + Add, then use that row's + once per key. You need five actions in total:
        Action nameKeys
        move_leftA and ← (done)
        move_rightD and →
        move_upW and ↑
        move_downS and ↓
        spinSpace (just one key; don't skip this one!)
        Before closing, check that all five are in the list, each with its keys underneath.
      7. Close the window with the Close button at the bottom. Godot saves Project Settings automatically.
      8. Pick what to control. Click 2D at the top, then the main tab above the viewport. In the Scene dock, click Icon, the Godot logo you added in Basics 1.Its icon in the Scene dock is the little Godot face, and the Inspector shows a Sprite2D section.
      9. Attach a script. Click the Attach Script button (scroll with a green +, top of the Scene dock). Check that Inherits says Sprite2D. In the Path box, change the file name at the end to mover.gd so it doesn't get confused with icon.svg. Click Create.
      10. Write the code. Select all (Ctrl+A) and replace it with this. Typing it yourself is good practice:
      11. Save and run. Ctrl+S, then click 2D, make sure the main tab is open, and press F6. Click inside the game window once so it has focus, then drive with WASD or the arrow keys and tap Space.
      12. Feel the difference. In the script, change is_action_just_pressed to is_action_pressed, save and run. Hold Space and watch the logo spin out of control, a quarter turn every frame. Then change it back. That's the difference from step 1, in your own game.
      🛠 Common problems
      Error: “The InputMap action "move_left" doesn't exist”

      The name in your code and the name in the Input Map don't match exactly. Check for typos, capital letters and spaces: it must be move_left, all lowercase with an underscore.

      Nothing moves when I press keys

      Click inside the game window first so it receives your key presses. Also check you pressed F6 with the main tab open, and that Icon has a scroll icon next to it in the Scene dock.

      Space doesn't spin the logo

      The spin action is probably missing. Open Project → Project Settings → Input Map, add an action called spin, click its + and press Space. Then save and run again.

      I pressed a key but don't see it in the list

      The action is collapsed. Click the small ▸ arrow to the left of the action's name to expand it. Each key shows underneath with “(Physical)” after it, which is normal.

      WASD works but the arrow keys don't (or the other way round)

      That action is missing its second event. Go back to Project → Project Settings → Input Map and click + on that action's row to add the missing key.

      Left moves it right, or up moves it down

      The order inside get_vector matters: left, right, up, down. Check your line matches the code above.

      I can't find the Input Map

      It's a tab along the top of the Project Settings window, next to General, not a setting inside General. Open it via the Project menu at the top left of the editor.

      The logo drives off the screen

      That's expected! There are no walls yet. Collisions come in Basics 5.

      Checkpoint

      The Godot logo glides smoothly with both WASD and the arrow keys, moves at the same speed diagonally, and turns a quarter turn each time you tap Space. Your coins are still spinning in the background.

      🎯 Your turn optional · no code given

      Hold Shift to sprint

      Make your logo move at double speed while the player holds Shift, and normal speed when they let go.

      Done when the logo glides normally, zooms while you hold Shift, and slows down again when you release it.

      You'll need: a new action in the Input Map, the right one of the three “pressed” questions, and a small if.

      💡 Hint 1 (a nudge)

      Start in the Input Map: add an action called sprint with Shift. Then think back to step 1: should running use pressed (every frame while held) or just_pressed (one frame)?

      💡 Hint 2 (more help)

      Make a new variable inside _process, like var current_speed := speed. If Input.is_action_pressed("sprint"), set it to speed * 2. Then use current_speed in the movement line instead of speed.

      ✅ Solution (try it yourself first!)
      func _process(delta: float) -> void:
      	var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
      
      	# Hold Shift to go twice as fast
      	var current_speed := speed
      	if Input.is_action_pressed("sprint"):
      		current_speed = speed * 2
      	position += direction * current_speed * delta
      
      	if Input.is_action_just_pressed("spin"):
      		rotation_degrees += 90

      Don't forget the Input Map: Project → Project Settings → Input Map → add sprint → + → press Shift.

      5

      Quick check

      Three questions, then you're done.

      🎉 Your game listens now.

      You can set up actions with several keys each, read them with pressed, just_pressed and get_vector, and you know which question to ask for which kind of control.

      Next · Basics 5: Collisions & physics bodies
      Walls, a real player and collecting your coins
      Start Basics 5 →