Mouse tracking when window is unfocused

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

Is it possible in the engine to track the mouse’s position when the window is unfocused and outside of the window? If so, how might that be done?

probably not what you were looking for, but if you need this feature for an FPS like mouse movement, set Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) (but be aware you’ll loose control of the mouse)

Andrea | 2021-01-27 09:13

:bust_in_silhouette: Reply From: Zylann

I know it is possible on Windows when using SDL by requesting the global mouse coordinates, but in Godot there is no API to do this. And tbh I wonder why would a game want to do such a thing while being unfocused and outside the screen.

If you have a compelling use case (and not just the raw feature without context), you could post a feature request on the proposals repository.

I’m unfamiliar with SDL but it sounds like a start. But it makes sense for such a feature to not already be in as it would seem like a sketchy feature to have in the API.

I was personally interested in making a character animate as a part of a stream, like a vtuber type of thing but I had particular features I wanted to make myself that other vtuber software doesn’t have like making the character appear to draw on a tablet when my cursor is on the screen tablet.

I would also imagine somebody making a map in a game that windowed and clicking and dragging to move about but having the mouse leave the window would interrupt that motion. Little things like that that make interfaces a bit more comfortable.

senshellshark | 2021-01-27 13:49

I would also imagine somebody making a map in a game that windowed and clicking and dragging to move about but having the mouse leave the window would interrupt that motion

This specific case is something different, and should be handled already if you use Control nodes and their input functions. This behavior with click+drag is common to many software and Godot should also support it. You can see it happen if you take any slider in the Godot GUI, and drag it until the mouse exits the window. It will still drag while being outside.

What it does not support is detecting the mouse while not actually dragging and while not being focused.

Zylann | 2021-01-27 16:41