How to simulate a click on screen

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

I don’t even know if godot can do this but is it possible to simulate a mouse click? Similar to how pyautogui works in python

:bust_in_silhouette: Reply From: PunchablePlushie

Haven’t worked with Python at all so not sure how pyautogui does it. But as far as I know, Godot has two ways to simulate input:

To use parse_input_event() you gotta create your own input event which is really easy actually.


For example, to create an event for the left mouse button at the position (10, 10):

var event_lmb = InputEventMouseButton.new()
event_lmb.position = Vector2(10, 10)

InputEventMouseButton class has a property called pressed which controls whether the button is… well, pressed/held down or not.
If you’re looking for a “full click”, AKA simulating someone pressing down the LMB and then releasing it, you can do something like this:

event_lmb.pressed = true
Input.parse_input_event(event_lmb)
event_lmb.pressed = false
Input.parse_input_event(event_lmb

The above code, combined with the first code will simulate a full left mouse click at position (10, 10).