Skip to content

_input: No InputEventMouse after click and drag when mouse is outside game window in the first window focus #100271

Open
@Liely118

Description

Tested versions

Reproducible in: v4.4.dev6.official [1f47e4c], v4.3.stable.official [77dcf97]

System information

Godot v4.4.dev6 - Windows 10.0.19045 - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 SUPER (NVIDIA; 31.0.15.3713) - AMD Ryzen 5 3600 6-Core Processor (12 threads)

Issue description

Any mouse interaction outside the game window will correctly not fire any InputEventMouse. But if the user clicks and drags something inside the window, an InputEventMouse is always fired, even when the mouse leaves the window, which is to be expected.
https://github.com/user-attachments/assets/b690596e-b2de-4e1b-8f53-249ef093cd54
Code in this example:

var pressed: bool

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT:
			pressed = event.pressed
			print(pressed)
	if pressed:
		$Icon.global_position = get_global_mouse_position()

However, if the window is not focused before the click and drag, no InputEventMouse is fired when the mouse leaves the window.
This can lead to an unexpected situation when a user clicks inside and releases outside the window; Since no InputMouseEventButton is fired outside the window, pressed is never updated.
https://github.com/user-attachments/assets/de45b373-b411-46c0-8f4e-c8f971094df5

As a workaround, you can do your mouse logic inside _process instead of _input.

func _process(_delta: float) -> void:
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		$Icon.global_position = get_global_mouse_position()

Steps to reproduce

  • Add this snippet into any script:
func _input(event: InputEvent) -> void:
	print(event)
  • Run the project and see that if the window is not focused before, clicking and dragging does not fire any InputMouseEvent when the mouse is outside the window.

Minimal reproduction project (MRP)

MouseEventOutsideWindowBug.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions