0 votes

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?

Godot version 3.2.3
in Engine by (18 points)

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)

1 Answer

+2 votes
Best answer

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.

by (27,576 points)
selected by

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.

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.

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.