Can I simulate my own InputEventKey events?

Godot Version

4.6

Question

I’m designing a virtual keyboard where the user can press buttons to emulate typing on a keyboard. Is there any way for my control to simulate keyboard events that would be processed by Godot’s GUI event handling system the same way pressing keys on a physical keyboard would? It would be nice if my existing controls could use the same GUI handling routines I’ve already written.

Yes. This is how you would generate a spacebar press for example.

var event = InputEventKey.new()
event.keycode = KEY_SPACE
event.pressed = true
Input.parse_input_event(event)
4 Likes