Trag mouse outsite window

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

i have a smal window in a size like a smartphone because i want to export it later to android. but also i want to play my game on windows too.

the player shoots in direction where the mouse cursor is, but godot cant find the direction if the cursor is outsite of the window.

can i bypass that?

You probaly should do this different: Try to develop two versions: For PC and android which have different window settings.

Schweini | 2019-08-23 07:25

No i don’t. its a realy smal skill game. it isn’t suposed to run in FullScreen.

gruen | 2019-08-23 10:02

:bust_in_silhouette: Reply From: Zylann

Relying on the mouse cursor outside of the actual system Window sounds like a bad idea, both technically and UX-wise. Godot can’t catch events happening outside of the window, unless the mouse is in a dragging operation (which is an actual feature of window managers).
If you want your game to run properly, the best you can do is to make the window larger or resizeable, really. That doesn’t mean you have to resize the game area: for this you can change the scaling modes if you want it to remain the same size. If you relied on OS window size in your code, then that’s also a bad idea since that assumption can easily break due to varying mobile resolutions anyways.

Other games do the same thing if you run them in window mode.
Gamemaker Studio does have that ability too

And i think godot also has that ability and ich just want to know how.
There must be an workarround

gruen | 2019-08-24 11:33

Which games do that? How would they even handle clicks outside the window? (which means the window will vanish out of focus :expressionless: )

It is possible to get the global mouse position on screen using OS-specific APIs, but that’s not a feature available through Godot API. Nobody needed this before.

Zylann | 2019-08-24 15:52

GTA 5 for excample.
and you cant click outsite of the window. you need to swap off with alt + tab

every game that you run in window mode disables the ability to click outsite of the screen.

there are always in nearly every game the ability to run in window mode or to run in borderless windowmode. but your cursor doesnt ever move outsite the window.

i just want the same thing. you aim in mousedirection and you should still aim in that direction if the mouse leaves the window.

it would be enough to disable the ability to leave the window.

i think

Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)

is nearly that what i am searching for.

gruen | 2019-08-26 07:19

:bust_in_silhouette: Reply From: Nesu

It might be old but:

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

will not let the mouse move outside of the window
This is used in this 3d demo for looking around: