How to detect a key press on a CollisionObject

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By blohod

I have a StaticBody2d that i want to detect when i press a key while moused over it. I am able to use _input_event() to detect mouse clicks but it does not seem to work for key presses. Ideally I want to detect an InputEventAction.

This works for mouse clicks, but no key press events are printed.

   func _input_event(viewport, event, shape_idx):
	print(event)
	if event is InputEventMouseButton :
		if event.button_index == BUTTON_LEFT and event.is_pressed():
			emit_signal("interact", self, tool_needed)
			print("goo")
:bust_in_silhouette: Reply From: exuin

Yeah, that’s because bodies don’t detect key presses. You need to use the _input or _unhandled_input function.