40. Godot input and PCA controls
func run() -> bool:
var action_name: StringName = &"inspect_close"
if not InputMap.has_action(action_name):
return false
return Input.is_action_pressed(action_name)Input actions need to exist in Godot’s InputMap. A PCA keybinding record and a Godot InputMap action are not automatically the same name/route. Check that the action exists; configure it in your Godot project or add it deliberately at runtime.
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey:
var key_event := event as InputEventKey
if key_event.pressed and not key_event.echo and key_event.keycode == KEY_F6:
Log("F6 reached the native script.")
get_viewport().set_input_as_handled()_unhandled_input is useful after GUI controls have had their chance. _input sees events earlier. Consume an event only when your feature owns it, or ordinary game controls can stop receiving it. Test focus, GUI typing, touch and controller routes as appropriate.
Direct Input polling can bypass adventure interaction rules. Use PCA’s movement/input actions to change the game’s control profile instead of simultaneously driving the same actor from another movement loop.
