#Is there a way to detect that the mouse isn't being moved?

1 messages · Page 1 of 1 (latest)

clear hatch
#

Hey, y'all! I'd like to make it so that if the player isn't moving the mouse, the cursor will disappear. I've learned that InputEventMouseMotion will work to detect mouse movement, but !InputEventMouseMotion doesn't seem to work for the opposite. Am I/my code just wrong, or is there something else I should be doing?

    Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
    
    
    if !InputEventMouseMotion:
        await get_tree().create_timer(1.0).timeout
        Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
    ```
lapis vigil
#

You will probably need some kind of timer for this. Detect mouse movement, and if you don't detect any mouse movement for X amount of time, hide the mouse

#

Something along these lines:


func _process(float: delta) -> void:
    time_since_mouse_move += delta
    if time_since_mouse_move > 0.5:
        Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
        
func _input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        time_since_mouse_move = 0
        Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)```
clear hatch
wild kraken
meager igloo
#

I can see where the intuition comes from, but this concept is event-driven programming; _input is only called when an input event fires, and never when one doesn't, so in theory if you're checking event is not InputEventMouseMovement you'd be checking if an input event isn't a mouse movement (e.g., on any keyboard input)

#

Nice to hear you got it working!