Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Liely118 opened this issue Dec 11, 2024 · 1 comment

Comments

@Liely118
Copy link

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

@Sauermann
Copy link
Contributor

Sounds related to #50187 and #33928.

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

No branches or pull requests

2 participants