Skip to content

[KBM] Fix modifier key remapped to non-modifier delivering WM_SYSKEYDOWN#47192

Open
oMatheusmol wants to merge 1 commit into
microsoft:mainfrom
oMatheusmol:fix/kbm-modifier-remap-syskeydown
Open

[KBM] Fix modifier key remapped to non-modifier delivering WM_SYSKEYDOWN#47192
oMatheusmol wants to merge 1 commit into
microsoft:mainfrom
oMatheusmol:fix/kbm-modifier-remap-syskeydown

Conversation

@oMatheusmol

Copy link
Copy Markdown

Summary of the Pull Request

When a modifier key (Ctrl/Alt/Shift) is remapped to a non-modifier key using
Keyboard Manager, the injected key event is delivered to applications as
WM_SYSKEYDOWN instead of WM_KEYDOWN. This causes unexpected behavior — for
example, remapping Left Alt to Backspace results in whole words being deleted
instead of single characters, because applications interpret WM_SYSKEYDOWN +
VK_BACK as Alt+Backspace.

The fix resets the modifier state with a suppress-flag key-up event before
injecting the target key, consistent with the existing approach used for the
Caps Lock remapping scenario.

PR Checklist

Detailed Description of the Pull Request / Additional comments

The root cause is that SendInput is called inside the low-level keyboard hook
callback before the original modifier event is suppressed. At that point the
modifier state is still active, so the OS delivers the injected key as
WM_SYSKEYDOWN (system key with Alt context) rather than WM_KEYDOWN.

This is the same mechanism that was already fixed for the Ctrl/Alt/Shift ↔
Caps Lock case. This PR extends the fix to cover modifier → non-modifier remaps.

Validation Steps Performed

  1. Remapped Left Alt → Backspace in Keyboard Manager
  2. Opened a text editor, typed text, pressed the remapped key
  3. Confirmed single characters are deleted instead of whole words
  4. All 93 unit tests pass (KeyboardManager.Engine.UnitTests)

@github-actions

Copy link
Copy Markdown

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, 👼 SARIF report, or 📝 job summary for details.

Unrecognized words (1)

DEFAULTTONEAREST

These words are not needed and should be removed defaulttonearest

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:oMatheusmol/PowerToys.git repository
on the fix/kbm-modifier-remap-syskeydown branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/24868842762/attempts/1' &&
git commit -m 'Update check-spelling metadata'
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@oMatheusmol

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes an issue in Keyboard Manager where remapping a modifier key (Ctrl/Alt/Shift) to a non-modifier can cause the injected target key to be interpreted with an unintended modifier context (e.g., Alt causing WM_SYSKEYDOWN semantics). The change aligns modifier→non-modifier remaps with the existing “reset modifier state via suppress-flag key-up” approach already used for Caps Lock-related cases.

Changes:

  • Add a suppress-flag key-up injection for the source modifier key before injecting the remapped target key when modifier → non-modifier remaps occur.
  • Add a unit test to validate that the suppress-flag injection happens for a representative modifier→non-modifier remap (LAlt → Backspace).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardEventHandlers.cpp Injects a suppress-flag key-up for the remapped modifier on keydown to clear modifier state before sending the target key.
src/modules/keyboardmanager/KeyboardManagerEngineTest/SingleKeyRemappingTests.cpp Adds a unit test asserting exactly one suppress-flag event is issued for a modifier→non-modifier remap.

@niels9001 niels9001 added the Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager label Apr 29, 2026
@oMatheusmol

Copy link
Copy Markdown
Author

Hi @MuyuanMS , just following up on this PR.

Could you please take a look when you have time? Let me know if any changes are needed. Thanks!

@oMatheusmol

Copy link
Copy Markdown
Author

Hi @niels9001 ,

Just following up on this PR since it has been open for a little over a month. The issue is still reproducible and the proposed fix is ready on my side.

Could you please let me know if there's anything else needed from me, or if any changes are required before review?

Thanks!

@MuyuanMS

MuyuanMS commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@MuyuanMS MuyuanMS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interestingly I was not able to reproduce the original bug - I remapped left alt to backspace and notepad shows WM_KEYDOWN even without the fix.
My guess is on issue is only reproducible on windows 10, and the fix itself has low risks and looks good to me

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

Labels

Product-Keyboard Manager Product-Keyboard Shortcut Manager Issues regarding Keyboard Shortcut Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[KBM] Remapping modifier key (Alt/Ctrl/Shift) to non-modifier key causes target key to be delivered as WM_SYSKEYDOWN

4 participants