Skip to content

Fix: Mouse bug -> switch getKeyState with getAsyncKeyState #20052

Merged
seanbudd merged 5 commits into
nvaccess:masterfrom
France-Travail:bugfix/mouseFail
May 6, 2026
Merged

Fix: Mouse bug -> switch getKeyState with getAsyncKeyState #20052
seanbudd merged 5 commits into
nvaccess:masterfrom
France-Travail:bugfix/mouseFail

Conversation

@Boumtchack
Copy link
Copy Markdown
Contributor

@Boumtchack Boumtchack commented May 4, 2026

Link to issue number:

fixes #19691

Summary of the issue:

When using the fullscreen magnifier in Center mode, clicking on controls in certain apps (Discord, Microsoft Teams, HyperX NGENUITY Beta) had no effect. The magnifier transform could shift between the physical button press and Windows applying it to the click coordinates, causing the click to land at the wrong logical position.

Description of user facing changes:

Mouse clicks on controls in apps such as Discord, Microsoft Teams, and HyperX NGENUITY Beta should work correctly when the fullscreen magnifier is running in Center mode.

Description of developer facing changes:

Replaced winUser.getKeyState / mouseHandler.isLeftMouseButtonLocked with winUser.getAsyncKeyState in FocusManager.getCurrentFocusCoordinates and FullScreenMagnifier._keepMouseCentered. Updated tests accordingly.

Description of development approach:

tKeyState is queue-based and can return a stale button state in the wx main thread when the message queue hasn't yet processed the click event. Switching to GetAsyncKeyState ensures the magnifier detects a button press immediately, preventing the Center mode transform from shifting between the physical press and Windows applying it to the click coordinates.

Testing strategy:

Unit

Known issues with pull request:

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@Boumtchack Boumtchack changed the title switch getKeyState with getAsyncKeyState Fix: Mouse bug -> switch getKeyState with getAsyncKeyState May 4, 2026
@Boumtchack Boumtchack marked this pull request as ready for review May 4, 2026 14:22
@Boumtchack Boumtchack requested a review from a team as a code owner May 4, 2026 14:22
@Boumtchack Boumtchack requested review from Copilot and seanbudd May 4, 2026 14:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses mis-targeted mouse clicks when the full-screen magnifier is running in Center mode by switching from message-queue-based key state to GetAsyncKeyState, so the magnifier can reliably detect mouse button presses immediately and avoid repositioning the cursor mid-click.

Changes:

  • Replace mouse-button detection with winUser.getAsyncKeyState in magnifier focus tracking (FocusManager.getCurrentFocusCoordinates).
  • Replace winUser.getKeyState with winUser.getAsyncKeyState in _keepMouseCentered to avoid interfering with active clicks.
  • Update unit tests to mock the new API usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
source/_magnifier/utils/focusManager.py Use getAsyncKeyState for left-button detection; broaden exception handling for review point retrieval.
source/_magnifier/fullscreenMagnifier.py Use getAsyncKeyState for left/right/middle button checks before cursor repositioning.
tests/unit/test_magnifier/test_focusManager.py Update tests to reflect the new async key state path.
tests/unit/test_magnifier/test_fullscreenMagnifier.py Update mocks/patching to target getAsyncKeyState.

Comment thread tests/unit/test_magnifier/test_focusManager.py Outdated
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label May 4, 2026
Copy link
Copy Markdown
Member

@seanbudd seanbudd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Boumtchack

@seanbudd
Copy link
Copy Markdown
Member

seanbudd commented May 5, 2026

Can you please make sure unit tests pass?

@seanbudd seanbudd merged commit faa8c5a into nvaccess:master May 6, 2026
31 of 37 checks passed
@github-actions github-actions Bot added this to the 2026.2 milestone May 6, 2026
@Boumtchack Boumtchack deleted the bugfix/mouseFail branch May 6, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants