![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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
![]() |
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:
Input.action_press()
and Input.action_release()
With these two you can simulate pressing an action that you’ve defined in the input map. However, as the docs point out: “This method will not cause any _input
calls. It is intended to be used with Input.is_action_pressed
and Input.is_action_just_pressed
”.
Input.parse_input_event()
This will simulate an InputEvent
which will be picked up by _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).