Spurious mouse events #8622

Closed
opened 2026-01-31 01:34:01 +00:00 by claunia · 3 comments
Owner

Originally created by @alabuzhev on GitHub (May 27, 2020).

Environment

Windows build number: 10.0.18363.836
Windows Terminal version (if applicable): N/A

Any other software? No

Steps to reproduce

  • Compile & run the following code:
#include <iostream>
#include <windows.h>

int main()
{
	const auto ConIn = GetStdHandle(STD_INPUT_HANDLE);
	DWORD Mode;

	if (GetConsoleMode(ConIn, &Mode))
		SetConsoleMode(ConIn, (Mode | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS) & ~ENABLE_QUICK_EDIT_MODE);

	INPUT_RECORD ir;
	DWORD n;
	int Count = 0;

	for (;;)
	{
		if (ReadConsoleInput(ConIn, &ir, 1, &n) && ir.EventType == MOUSE_EVENT)
		{
			++Count;
			std::cout << "MOUSE_EVENT_RECORD: " << Count << std::endl;
		}
	}
}
  • Make sure that it reports mouse events when you hover the mouse pointer over the console window.

Case 1: spurious events on focus change

  1. Position the mouse pointer over the console window and stop touching the mouse.
  2. Press Win key on the keyboard to open the Start menu. Press it again to close the menu.

Expected behavior

No mouse events - the mouse hasn't been moved.

Actual behavior

Multiple mouse events when the console window receives the focus back.
When the mouse pointer is positioned outside the console window the issue doesn't happen.

Case 2: spurious events on window resize

  1. Position the mouse pointer over the console window and stop touching the mouse.
  2. Press Win+Up key to maximise the window.
  3. Press Win+Down key to restore the window.

Expected behavior

No mouse events - the mouse hasn't been moved.

Actual behavior

A single mouse event on every resize.
When the mouse pointer is positioned outside the area, reachable by the window (e.g. over the taskbar) the issue doesn't happen.

Originally created by @alabuzhev on GitHub (May 27, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.18363.836 Windows Terminal version (if applicable): N/A Any other software? No ``` # Steps to reproduce <!-- A description of how to trigger this bug. --> - Compile & run the following code: ```C++ #include <iostream> #include <windows.h> int main() { const auto ConIn = GetStdHandle(STD_INPUT_HANDLE); DWORD Mode; if (GetConsoleMode(ConIn, &Mode)) SetConsoleMode(ConIn, (Mode | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS) & ~ENABLE_QUICK_EDIT_MODE); INPUT_RECORD ir; DWORD n; int Count = 0; for (;;) { if (ReadConsoleInput(ConIn, &ir, 1, &n) && ir.EventType == MOUSE_EVENT) { ++Count; std::cout << "MOUSE_EVENT_RECORD: " << Count << std::endl; } } } ``` - Make sure that it reports mouse events when you hover the mouse pointer over the console window. # Case 1: spurious events on focus change 1. Position the mouse pointer over the console window and stop touching the mouse. 2. Press <kbd>Win</kbd> key on the keyboard to open the Start menu. Press it again to close the menu. # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> No mouse events - the mouse hasn't been moved. # Actual behavior <!-- What's actually happening? --> Multiple mouse events when the console window receives the focus back. When the mouse pointer is positioned outside the console window the issue doesn't happen. # Case 2: spurious events on window resize 1. Position the mouse pointer over the console window and stop touching the mouse. 2. Press <kbd>Win</kbd>+<kbd>Up</kbd> key to maximise the window. 3. Press <kbd>Win</kbd>+<kbd>Down</kbd> key to restore the window. # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> No mouse events - the mouse hasn't been moved. # Actual behavior <!-- What's actually happening? --> A single mouse event on every resize. When the mouse pointer is positioned outside the area, reachable by the window (e.g. over the taskbar) the issue doesn't happen.
claunia added the Resolution-By-DesignNeeds-Tag-FixNeeds-Attention labels 2026-01-31 01:34:01 +00:00
Author
Owner

@DHowett commented on GitHub (May 28, 2020):

Thinking about this, I'm going to call both of these "by design"...

In case 1, the mouse has once again become visible to the console. It's not visible while the console doesn't have focus, and it's moved out of nonexistence into existence.

In case 2, the coordinates are definitely different when I do it. The mouse, relative to the buffer, has moved. An application could be reasonably expected to want to know about this.

What's broken because of this?

@DHowett commented on GitHub (May 28, 2020): Thinking about this, I'm going to call both of these "by design"... In case 1, the mouse has once again become visible to the console. It's not visible while the console doesn't have focus, and it's moved out of nonexistence into existence. In case 2, the coordinates are definitely different when I do it. The mouse, relative to the buffer, _has_ moved. An application could be reasonably expected to want to know about this. What's broken because of this?
Author
Owner

@DHowett commented on GitHub (May 28, 2020):

(This seems to reproduce with the legacy console host, as well -- it's highly conserved behavior, and we're not really planning on changing behaviors apps might have depended on unless there's a darned good reason.)

@DHowett commented on GitHub (May 28, 2020): (This seems to reproduce with the legacy console host, as well -- it's highly conserved behavior, and we're not really planning on changing behaviors apps might have depended on unless there's a darned good reason.)
Author
Owner

@alabuzhev commented on GitHub (May 28, 2020):

In case 1, the mouse has once again become visible to the console. It's not visible while the console doesn't have focus, and it's moved out of nonexistence into existence.

  • So dwEventFlags = MOUSE_MOVED means "moved into existence"? That's a nice way to put it :)
  • The keyboard is moved out of nonexistence into existence as well, why there are no KEY_EVENTs?

What's broken because of this?

An app renders a pseudographic UI, including menus. In those menus the active item follows the mouse pointer on hovering, just like in the regular Windows UI.
A user opens a menu (e.g. a list of recent commands), looks at it, walks up and down using keyboard keys, stops at some item, meditates, decides that more screen space is needed to make a decision (e.g. because the window size is too small and the items are truncated) and maximises the window via a keyboard shortcut. Suddenly the active item changes "randomly" (by following the mouse pointer). The user is clearly confused because they weren't even holding the mouse in their hands at the moment.

@alabuzhev commented on GitHub (May 28, 2020): > In case 1, the mouse has once again become visible to the console. It's not visible while the console doesn't have focus, and it's moved out of nonexistence into existence. - So dwEventFlags = MOUSE_MOVED means "moved into existence"? That's a nice way to put it :) - The keyboard is moved out of nonexistence into existence as well, why there are no KEY_EVENTs? > What's broken because of this? An app renders a pseudographic UI, including menus. In those menus the active item follows the mouse pointer on hovering, just like in the regular Windows UI. A user opens a menu (e.g. a list of recent commands), looks at it, walks up and down using keyboard keys, stops at some item, meditates, decides that more screen space is needed to make a decision (e.g. because the window size is too small and the items are truncated) and maximises the window via a keyboard shortcut. Suddenly the active item changes "randomly" (by following the mouse pointer). The user is clearly confused because they weren't even holding the mouse in their hands at the moment.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8622