+2 votes

I'm trying to implement scrolling the screen when you move the mouse to the edge of the screen, like in a Blizzard RTS. When the game is fullscreen, there's no problem. But when the game is windowed and I move the mouse off of the window, gettree().getroot().getmouseposition() seems to think that the mouse is still on the window at the last position that it actually was. For example: the mouse's x won't be less than zero even if I move it left off of the window.

The DisplayServer class has what looks like some relevant values in the WindowEvent enum, but it looks like what I want to actually do (just detect if the mouse has left and/or returned to the window) is either unimplemented or undocumented. Or I'm missing something obvious.

Godot version Godot 4 alpha 6
in Engine by (39 points)

1 Answer

+2 votes
Best answer

it in notification

func _notification(what):
    if what == NOTIFICATION_WM_MOUSE_ENTER:
        print("enter")
    elif what == NOTIFICATION_WM_MOUSE_EXIT:
        print("exit")

you could also try

if what == NOTIFICATION_WM_FOCUS_IN:
    print("focus in")
elif what == NOTIFICATION_WM_FOCUS_OUT:
    print("focus out")

to detect is user tab to other window

by (133 points)
selected by

Perfect! Exactly what I was looking for!

And now I have some idea of how to use the _notification() function!

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 Frequently asked questions and 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 [email protected] with your username.