godot-input-handling
Original:🇺🇸 English
Translated
Expert patterns for input handling covering InputMap actions, InputEvent processing, controller support, rebinding, deadzones, and input buffering. Use when setting up player controls, implementing input systems, or adding gamepad/accessibility features. Keywords InputMap, InputEvent, gamepad, controller, rebinding, deadzone, input buffer.
7installs
Added on
NPX Install
npx skill4agent add thedivergentai/gd-agentic-skills godot-input-handlingTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Input Handling
Handle keyboard, mouse, gamepad, and touch input with proper buffering and accessibility support.
Available Scripts
input_buffer.gd
Input buffering for responsive controls - buffers actions for 150ms to ensure tight game feel.
input_remapper
Runtime input rebinding with conflict detection and save/load persistence.
MANDATORY - For Responsive Controls: Read input_buffer.gd before implementing jump/dash mechanics.
NEVER Do in Input Handling
- NEVER poll input in for gameplay actions — Use
_process()or_physics_process()_process()` = frame-rate dependent, causes input drops at low FPS._unhandled_input() - NEVER use hardcoded key checks (,
KEY_W) — Use InputMap actions. Hardcoded keys = no rebinding, breaks non-QWERTY keyboards.KEY_SPACE - NEVER ignore controller deadzones — Stick drift at 0.05 magnitude = character walks alone. ALWAYS implement with 0.15-0.2 deadzone.
Input.get_axis() - NEVER assume single input device — Player might switch keyboard → gamepad mid-session. Listen to and update UI prompts dynamically.
Input.joy_connection_changed - NEVER use for gameplay actions —
//_input()fires for ALL events (including UI). Use_input()which only fires if UI didn't consume the event._unhandled_input() - NEVER forget input buffering for responsive controls — Player presses jump 50ms before landing? Without buffer, jump is lost. Buffer inputs for 100-150ms for tight game-feel.
InputMap Actions
Setup: Project Settings → Input Map → Add action
gdscript
# Check if action pressed this frame
if Input.is_action_just_pressed("jump"):
jump()
# Check if action held
if Input.is_action_pressed("fire"):
shoot()
# Check if action released
if Input.is_action_just_released("jump"):
release_jump()
# Get axis (-1 to 1)
var direction := Input.get_axis("move_left", "move_right")
# Get vector
var input_vector := Input.get_vector("left", "right", "up", "down")InputEvent Processing
gdscript
func _input(event: InputEvent) -> void:
if event is InputEventKey:
if event.keycode == KEY_ESCAPE and event.pressed:
pause_game()
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
click_position = event.positionGamepad Support
gdscript
# Detect controller connection
func _ready() -> void:
Input.joy_connection_changed.connect(_on_joy_connection_changed)
func _on_joy_connection_changed(device: int, connected: bool) -> void:
if connected:
print("Controller ", device, " connected")Reference
Related
- Master Skill: godot-master