Mouse Highlighter is a utility that visualizes mouse clicks by displaying a highlight effect around the cursor when clicked.
Mouse Highlighter runs within the PowerToys Runner process and draws visual indicators (typically circles) around the mouse cursor when the user clicks.
src/modules/MouseUtils/MouseHighlighter/MouseHighlighter.cpp- Contains the main implementation- Key function:
WndProc- Handles window messages and mouse events
When the utility is enabled:
-
A background thread is created to run the mouse highlighter logic asynchronously:
std::thread([=]() { MouseHighlighterMain(m_hModule, m_highlightSettings); }).detach();
-
The Highlighter instance is initialized and configured with user settings:
Highlighter highlighter; Highlighter::instance = &highlighter; highlighter.ApplySettings(settings); highlighter.MyRegisterClass(hInstance);
-
A highlighter window is created:
instance->CreateHighlighter(); -
The utility:
- Registers a custom window class
- Creates a transparent window for drawing visuals
- Handles the
WM_CREATEmessage to initialize the Windows Composition API (Compositor, visuals, and target)
The activation process works as follows:
-
Shortcut Detection
- The system detects when the activation shortcut is pressed
- A global hotkey listener (registered with
RegisterHotKeyor similar hook) detects the shortcut
-
Message Transmission
- A message (like
WM_SWITCH_ACTIVATION_MODE) is sent to the highlighter window viaPostMessage()orSendMessage()
- A message (like
-
Window Procedure Handling
- The
WndProcof the highlighter window receives the message and toggles between start and stop drawing modes:case WM_SWITCH_ACTIVATION_MODE: if (instance->m_visible) instance->StopDrawing(); else instance->StartDrawing();
- The
-
Drawing Activation
-
If turning ON,
StartDrawing()is called, which:- Moves the highlighter window to the topmost position
- Slightly offsets the size to avoid transparency bugs
- Shows the transparent drawing window
- Hooks into global mouse events
- Starts drawing visual feedback around the mouse
-
If turning OFF,
StopDrawing()is called, which:- Hides the drawing window
- Removes the mouse hook
- Stops rendering highlighter visuals
-
When the mouse highlighter is active:
- A low-level mouse hook detects mouse button events
- On click, the highlighter draws a circle (or other configured visual) at the cursor position
- The visual effect fades over time according to user settings
- Each click can be configured to show different colors based on the mouse button used
To debug Mouse Highlighter:
- Attach to the PowerToys Runner process directly
- Set breakpoints in the
MouseHighlighter.cppfile - Be aware that visual effects may appear different or stuttery during debugging due to the debugger's overhead
- There is a reported bug where the highlight color stays on after toggling opacity to 0
- This issue has been present for more than six months and can still be reproduced in recent PowerToys releases