How to get mouse/cursor position of monitor/OS?

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

Hello,

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

get_mouse_position() 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.

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?

AlienBuchner | 2019-09-24 21:02

:bust_in_silhouette: Reply From: MintSoda

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.)