Create an InputEventKey
event, define the scancode
and pressed
state, and use Input.parse_input_event()
to feed it to your game.
func simulate_keypress():
var a = InputEventKey.new()
a.scancode = KEY_ENTER
a.pressed = true # change to false to simulate a key release
Input.parse_input_event(a)
See here for a list with all scancodes.