AgentSkillsCN

setup-input

为游戏配置输入动作。在 project.godot 中新增输入动作,并同步编写相应的输入处理代码。当您需要为玩家添加控制方案、菜单导航功能,或是实现交互式输入时,此功能将助您事半功倍。

SKILL.md
--- frontmatter
name: setup-input
description: Configure input actions for the game. Add new input actions to project.godot and create the corresponding input handling code. Use when adding player controls, menu navigation, or interaction inputs.
argument-hint: <action-name-or-description> [key-bindings...]
disable-model-invocation: true

Set Up Input Actions

Configure input actions for: $ARGUMENTS

Step 1 — Research (MANDATORY — do not skip)

You MUST complete ALL of these before writing any code:

  1. Call the godot-docs skill for input classes:
    code
    activate_skill("godot-docs") # Look up Input, InputEvent, and InputMap. I need properties, methods, and tutorials for InputEvent handling, input examples, and gamepadcontroller support.
    
  2. Read the node lifecycle best practices (input callbacks have specific ordering):
    code
    Read("docsbest-practices/05-node-lifecycle.md")
    

Step 2 — Define Input Actions

Standard JRPG input actions:

Movement

ActionKeyboardGamepadDescription
move_upW, UpLeft Stick Up, D-Pad UpMove character up
move_downS, DownLeft Stick Down, D-Pad DownMove character down
move_leftA, LeftLeft Stick Left, D-Pad LeftMove character left
move_rightD, RightLeft Stick Right, D-Pad RightMove character right

Interaction

ActionKeyboardGamepadDescription
interactE, EnterA / CrossTalk to NPC, pick up item, confirm
cancelEscape, BackspaceB / CircleCancel, close menu, go back
menuTab, MStartOpenclose pause menu
runShiftX / Square (hold)Sprintrun

Combat

ActionKeyboardGamepadDescription
attackSpace, ZA / CrossBasic attack in combat
defendXY / TriangleDefend in combat
skill_menuCRB / R1Open skill selection
item_menuVLB / L1Open item selection
fleeFSelect / BackAttempt to flee

UI Navigation (built-in Godot actions)

  • ui_accept — Already mapped to Enter, Space, Gamepad A
  • ui_cancel — Already mapped to Escape, Gamepad B
  • ui_updownleftright — Already mapped to arrows, gamepad d-pad

Step 3 — Modify project.godot

Read the current gameproject.godot file and add input actions to the [input] section.

Input Action Format in project.godot

ini
[input]

move_up={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}

Important: The input action format in project.godot is very verbose. It is easier and more reliable to instruct the user to add input actions via the Godot editor: Project > Project Settings > Input Map. Only modify project.godot directly if you are confident in the format.

Step 4 — Create Input Handling Code

Movement Input Pattern

gdscript
func _physics_process(delta: float) -> void:
    var input_dir := Input.get_vector(
            "move_left", "move_right",
            "move_up", "move_down",
    )
    velocity = input_dir * speed
    move_and_slide()

Action Input Pattern

gdscript
func _unhandled_input(event: InputEvent) -> void:
    if event.is_action_pressed("interact"):
        _try_interact()
    elif event.is_action_pressed("menu"):
        _toggle_menu()
    elif event.is_action_pressed("cancel"):
        _handle_cancel()

Input State Checking

gdscript
# In _process or _physics_process
if Input.is_action_pressed("run"):
    speed = RUN_SPEED
else:
    speed = WALK_SPEED

# Just pressed (single frame)
if Input.is_action_just_pressed("attack"):
    _start_attack()

Step 5 — Report

After setup, report:

  1. Input actions added or recommended
  2. Code patterns created
  3. Editor tasks — which actions the user needs to add via Project Settings > Input Map (with specific keybutton bindings)
  4. How existing scripts should reference these actions