Preserve ENHANCED_KEY for direct key events (Alt up, F7 down) - #20619
Open
TheJesper wants to merge 1 commit into
Open
Preserve ENHANCED_KEY for direct key events (Alt up, F7 down)#20619TheJesper wants to merge 1 commit into
TheJesper wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
4 tasks
Key events that reach us via WindowEmperor::_dispatchSpecialKey (F7 down, Alt up) were forwarded through IDirectKeyListener::OnDirectKeyEvent without the extended-key bit from lParam. TermControl therefore never set ENHANCED_KEY on these events, so releasing e.g. RightAlt produced an INPUT_RECORD that is indistinguishable from a LeftAlt release. Thread an "extended" flag through the OnDirectKeyEvent chain and set EnhancedKey in TermControl, matching what the regular _KeyHandler path derives from CorePhysicalKeyStatus.IsExtendedKey. Adds a TerminalCore unit test verifying that win32-input-mode key events retain ENHANCED_KEY on both press and release of RightAlt. Closes microsoft#18120
TheJesper
force-pushed
the
fix/18120-enhanced-key-rightalt-release
branch
from
August 30, 2026 13:47
06c5cc2 to
0c9ef02
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
WindowEmperor::_dispatchSpecialKeyintercepts Alt key-up (and F7 key-down) to handle the window menu before XAML sees them. These events get forwarded throughIDirectKeyListener::OnDirectKeyEvent, but the extended-key bit fromlParamwas dropped along the way. Without it,TermControlcan't distinguish RightAlt from LeftAlt on release, so a RightAlt key-up produces anINPUT_RECORDidentical to LeftAlt. The key press works fine because it goes through the regular XAML_KeyHandlerpath whereCorePhysicalKeyStatus.IsExtendedKeyis available.Fix: thread an
extendedbool through theOnDirectKeyEventchain and setControlKeyStates::EnhancedKeywhen true - same thing the regular key path already does. Changed signature:OnDirectKeyEvent(vkey, scanCode, down, extended).References and Relevant Issues
Closes #18120
Detailed Description of the Pull Request / Additional comments
The asymmetry happens because the emperor intercepts Alt-up for system menu handling - it needs to swallow it before XAML turns it into a menu activation. That interception path (
_dispatchSpecialKey) only extracted the virtual key, scan code, and up/down state fromlParam, ignoring bit 24 (the extended-key flag). This PR extracts that bit and passes it through.Validation Steps Performed
Built two copies locally (x64 Debug, VS 2026 / SDK 10.0.26100), registered with
Add-AppxPackage -Register, ran on Windows 11. Used a smallReadConsoleInputWrepro tool with win32-input-mode enabled (\x1b[?9001h), pressing RightAlt and LeftAlt on a Swedish keyboard layout (where RightAlt is AltGr, so Windows translates it to Ctrl+Alt - hence the(auto)LeftCtrl events).Before (parent commit 079d1cc) - RightAlt release loses its identity:

After (this branch) - works correctly:

Also added
InputTest::Win32KeyEventsRetainEnhancedKeywhich checks that win32-input-mode encodes the flag correctly for both press and release of RightAlt. Passes locally.PR Checklist