+1 vote

Hello,

I need to be able to detect whether or not the mouse is over the game window or not.

getmouseposition() doesn't give the current mouse location when it's outside of the game window.

Is there a way to get the "real" mouse position of the user's monitor/OS?

Or at the very least, is there a way to detect whether the mouse has entered/left the game window?

Thank you.

in Engine by (23 points)

Yeah, same question here. It seems this can't be solved neither by

get_viewport().get_mouse_position()

nor by

get_global_mouse_position()

These functions don't return a value outside the window. Unfortunately the Docs don't say a word here, do they?

1 Answer

0 votes

you could do

var global_mouse_pos = OS.get_window_position() + get_global_mouse_position()

If you're making an OS-related app with Godot, you might need some OS api modules from C# or other languages via GDNative plugins. (Maybe too late for advice.)

by (302 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.