0 votes

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?

in Engine by (18 points)

1 Answer

+2 votes
Best answer

guiinput 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()
by (891 points)
selected by

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.