How to catch keystroke in control gui_input?

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

Hi there,
I’ve got a TitleScreen (Controller) scene with an gui_input Signal. The handling looks like this:

func _on_TitleScreen_gui_input(event):
  GLOBAL.debug_InputEvent("_gui_input: ",event)

in global.md:

func debug_InputEvent(aMessage, event):
  var eventStr

  if event is InputEventKey: eventStr = "InputEventKey"
  elif event is InputEventMouseButton: eventStr = "InputEventMouseButton"
  #elif event is InputEventMouseMotion: eventStr = "InputEventMouseMotion"
  elif event is InputEventJoypadMotion: eventStr = "InputEventJoypadMotion"
  elif event is InputEventJoypadButton: eventStr = "InputEventJoypadButton"
  elif event is InputEventScreenTouch: eventStr = "InputEventScreenTouch"
  elif event is InputEventScreenDrag: eventStr = "InputEventScreenDrag"
  elif event is InputEventAction: eventStr = "InputEventAction"
  elif event is InputEvent: eventStr = "Unhandled InputEvent"  

  print(aMessage + eventStr)

I would expect when i hit the escape key that i get a print out of InputEventKey or InputEventAction, instead its always Unhandled, because of commented out mousemotion.

How do i catch a keystroke?

:bust_in_silhouette: Reply From: flurick

_gui_input for gui stuff if you want to list all input there is _input(), so something like this?

func _input(event):
	print(event.as_text())
	if event is InputEventKey:
		if event.scancode == KEY_ESCAPE:
			accept_event()

Thanks, that worked.

I thought it had no _input signal as it wasn’t shown up anywhere, even not in the inline documentation, and i didn’t no came up to test it.

Thinking about it a bit deeper, it’s logical, as it is inherited by the node class.

acambule | 2018-10-17 06:45