How to tell if mouse is off-screen?

We have UIS:GetMouseLocation() as well as mouse.X/mouse.Y to tell the coordinates of the mouse while it’s within game window bounds, however it does not tell us if it leaves them.

There’s the events UIS:WindowFocusReleased and UIS:WindowFocused, but those only work if the player clicks while the mouse is off the screen.

Is there something to tell that the mouse has left the screen, but the player has not yet clicked off the screen?

1 Like

I think that MouseLeave would probably do the job, or help in some aspect?

That won’t work, that’s only for UI. Even if you do make a UI that’s maximum sized, it won’t work, since when your mouse leaves the window, it doesn’t track the mouse anymore from there unless it’s back in the frame.

This is impossible I think, since there’d be a script for an anti-tab-out thing

You can use Mouse.X and mouse.Y with workspace.CurrentCamera.ViewportSize which will give the screen size in pixels and if the mouse position is larger, then it left, is that what you Meant?

1 Like

Mouse.X/mouse.Y stop changing if the mouse leaves the screen.

Why dont you use This then

I mentioned that in my post - it only works if the player clicks off the screen, not if it’s outside window bounds but the player hasn’t yet clicked off.

Exactly exactly, ill try to think of something for you

Not the best solution, but I guess FullscreenChanged event could be used to force fullscreen - making it so the mouse can’t move outside of window bounds, combined with WindowFocusReleased to catch any alt+tab stuff.

Hmm actually use the focus released and add a function which detects if he click alt + tab or windows + tab or windows + ctrl + left / right arrow keys

I’m not sure what you mean - FocusReleased is what detects alt+tab type stuff

I meant use a function to check if he clicked the button combinations and in the same time have the focus released, like that, you covered every possible way of him tapping out

Wait i got you wrong ;-;

Then when he tabs out it doesn’t detect until he clicks? Can i know whats that for? I could get a better approach

When they tab out, WindowFocusReleased is triggered.

My problem is I have it so the camera moves as the mouse approaches the sides of the screen, but if you move it to windows taskbar then WindowFocusReleased doesn’t trigger until you click on the taskbar - but it’s not updating the mouse position while it’s past the bounds and therefore continues moving based on the last position of mouse.Y which if they move it fast enough misses the edge camera movement entirely.

So the camera just keeps moving up / down?

The problem is moreso that it doesn’t start moving because it doesn’t know the mouse is past screen bounds. Basically imagine you have it at position 1400, but screen movement starts at 1450, and they move it so the next frame it’s off-screen - the screen movement never started although it probably should have.

This isn’t a problem in fullscreen mode because it can’t move past screenbounds though, so I can make it so that feature is only included if fullscreen mode is enabled.

That wont be so good, not everyone would like that… Lets try to think of a way around this

Why not just make a frame that takes up the entire screen and detect when the mouse leaves it?

Same reason Sub2rubixxman said, that doesn’t register when it moves off-screen.