0 votes

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

Godot version 3.3
in Engine by (12 points)

1 Answer

+2 votes

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).

by (170 points)
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.