Is there a way to emulate a user input such that it calls unhandled input?

Godot Version

4.2 stable


I’m trying to write some unit tests in gdUnit and I’d like to emulate user input, which I handle on my character using unhandled input function. I’ve tried using Input but this I presume isn’t treated as an unhandled input under the hood. Is there a way to generate unhandled input without user input?

I think this is probably my bad layout - as I have Input.get_vector() under my unhandled input which strikes me as maybe not a correct approach. Open to suggestions

func controller_unplugged():
    var pause_event =
    pause_event.action = "pause"
    pause_event.pressed = true

I use these lines of code to emulate the “pause” action being pressed when the player disconnects a controller. The game checks whether the player presses the “pause” action in the _unhandled_input(event) function. I believe this should work for you as well.

First, create a new action event with and assign it to a temporary variable; something like var emulated_action = Next, set this action’s action property to the corresponding action as String and the pressed property to true. Finally, parse the event by calling Input.parse_input_event(emulated_action).

Is this what you are looking for?


That looks right I’ll have to try it out but I presume it’ll solve it thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.