Set mouse position outside game window

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

I’m trying to set my mouse position with help of some old article, but “Input.warp_mouse_pos(Vector2())” brings up an error and “get_viewport().warp_mouse(Vector2())” seems to be constrained to the game window and I want to use the mouse outside the game (on my desktop etc.)

How do I set mouse position outside my game? (preferably in GDScript, but Godot’s C++ will also do)

:bust_in_silhouette: Reply From: boston2029

I don’t know if you can do that because then you could make a virus that moves your mouse and stuff just with Godot. If you said that you can move it anywhere in the game window, try making your game fullscreen. That’s all I got.

I will not be making my project fullscreen, because the project is supposed to run in the background minimized and make my mouse move on my Desktop, in Osu!, Aseprite, etc.

I have used a C++ autoclicker and it has been able to move my mouse freely so I’m pretty sure Godot’s C++ can also do it. (Or does Godot limit C++ usage somehow?)

Vekepihvi | 2021-04-14 05:12

:bust_in_silhouette: Reply From: Vekepihvi

Apparently you can do this using Godot C++, but that seems to only work on Windows and it’s also a lot harder to set up than the later option. I recommend using C# with this post’s answer.