Skip to content

Preserve ENHANCED_KEY for direct key events (Alt up, F7 down) - #20618

Closed
TheJesper wants to merge 1 commit into
microsoft:mainfrom
TheJesper:fix/18120-enhanced-key-rightalt-release
Closed

Preserve ENHANCED_KEY for direct key events (Alt up, F7 down)#20618
TheJesper wants to merge 1 commit into
microsoft:mainfrom
TheJesper:fix/18120-enhanced-key-rightalt-release

Conversation

@TheJesper

@TheJesper TheJesper commented Aug 28, 2026

Copy link
Copy Markdown

Summary of the Pull Request

Key events that reach the app through WindowEmperor::_dispatchSpecialKey (F7 down, Alt up) are forwarded through IDirectKeyListener::OnDirectKeyEvent without the extended-key bit from lParam. TermControl::OnDirectKeyEvent therefore never sets ENHANCED_KEY on these events, so releasing e.g. RightAlt produces an INPUT_RECORD that is indistinguishable from a LeftAlt release — while the key press (which goes through the regular XAML _KeyHandler path with CorePhysicalKeyStatus.IsExtendedKey) correctly carries the flag.

This PR threads an extended parameter through the OnDirectKeyEvent chain (WindowEmperorAppHostTerminalWindow → focus-tree listeners → TermControl) and sets ControlKeyStates::EnhancedKey in TermControl, matching the regular key path.

References and Relevant Issues

Closes #18120

Validation Steps Performed

Full local build: CascadiaPackage built locally (x64 Release, VS 2026 / SDK 10.0.26100), registered with Add-AppxPackage -Register and run on Windows 11.

Live repro validation: ran the ReadConsoleInputW sample from #18120 inside the locally built terminal and pressed/released RightAlt (extended) and LeftAlt (non-extended):

down: 1, ENHANCED_KEY: 1, ctrl: 0x129, vcod: 0x12, scod: 0x38   <- RightAlt press (AltGr: LeftCtrl interleaved)
down: 0, ENHANCED_KEY: 1, ctrl: 0x120, vcod: 0x12, scod: 0x38   <- RightAlt RELEASE: flag now present (the bug)
down: 1, ENHANCED_KEY: 0, ctrl: 0x22,  vcod: 0x12, scod: 0x38   <- LeftAlt press (correctly no flag)
down: 0, ENHANCED_KEY: 0, ctrl: 0x20,  vcod: 0x12, scod: 0x38   <- LeftAlt release (correctly no flag)

Before this change the RightAlt release line reported ENHANCED_KEY: 0 (per the issue). Screen recording of the locally built terminal running the repro:

validation recording

Screenshot: validation-screenshot.png · Raw log: keyrepro.log · Repro source: keyrepro.cpp

Unit test: new InputTest::Win32KeyEventsRetainEnhancedKey in UnitTests_TerminalCore verifies win32-input-mode encodes ENHANCED_KEY in the Cs parameter for both press (Cs=257) and release (Cs=256) of RightAlt via Terminal::SendKeyEvent. Passes locally via TAEF (x64 Release), together with the pre-existing InputTest methods.

PR Checklist


This contribution was made with AI assistance (Claude Code); all changes were built, run and validated locally as described above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A69HPN9EZs1GJpgrYnjn2F

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

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A69HPN9EZs1GJpgrYnjn2F
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@zadjii-msft

Copy link
Copy Markdown
Member

TerminalControl, TerminalCore, TerminalSettingsModel and the unit test projects build locally; full TerminalApp/WindowsTerminal verification deferred to CI due to a local SDK XamlCompiler issue unrelated to this change (draft until CI is green).

Nope. We're not gonna accept any contributions unless you can build and validate the code yourself locally. Feel free to re-open the PR when you can do that. Make sure to include a screen recording of what this feature looks like, so that we can be sure that you're actually running this locally.

@zadjii-msft Mike Griese (zadjii-msft) added spam thought we wouldn't notice, but we did npc 🤖 labels Aug 28, 2026
@TheJesper

Copy link
Copy Markdown
Author

Fair enough — reopening now that I can. I've built the full CascadiaPackage locally (VS 2026, SDK 26100), registered and ran it, and validated the fix live with the ReadConsoleInputW repro from the issue: RightAlt release now reports ENHANCED_KEY (LeftAlt correctly doesn't). The PR body has the screen recording of the locally built terminal running the repro, plus the raw log and the repro source. Unit test Win32KeyEventsRetainEnhancedKey passes via TAEF locally as well.

@TheJesper

Copy link
Copy Markdown
Author

GitHub wouldn't let me reopen this one, so the validated version continues in #20619 (full local CascadiaPackage build, live repro validation with recording, TAEF test passing).

@TheJesper

Copy link
Copy Markdown
Author

Superseded by #20619, opened from wrong branch.

@DHowett

Copy link
Copy Markdown
Member

did you somehow have to create an entirely new branch to comply with Mike's request? That is... highly unusual.

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

Labels

npc 🤖 spam thought we wouldn't notice, but we did

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENHANCED_KEY flag missing when releasing RightAlt

3 participants