Preserve ENHANCED_KEY for direct key events (Alt up, F7 down) - #20618
Preserve ENHANCED_KEY for direct key events (Alt up, F7 down)#20618TheJesper wants to merge 1 commit into
Conversation
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: There may be pipelines that require an authorized user to comment /azp run to run. |
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. |
|
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. |
|
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). |
|
Superseded by #20619, opened from wrong branch. |
|
did you somehow have to create an entirely new branch to comply with Mike's request? That is... highly unusual. |
Summary of the Pull Request
Key events that reach the app through
WindowEmperor::_dispatchSpecialKey(F7 down, Alt up) are forwarded throughIDirectKeyListener::OnDirectKeyEventwithout the extended-key bit fromlParam.TermControl::OnDirectKeyEventtherefore never setsENHANCED_KEYon these events, so releasing e.g. RightAlt produces anINPUT_RECORDthat is indistinguishable from a LeftAlt release — while the key press (which goes through the regular XAML_KeyHandlerpath withCorePhysicalKeyStatus.IsExtendedKey) correctly carries the flag.This PR threads an
extendedparameter through theOnDirectKeyEventchain (WindowEmperor→AppHost→TerminalWindow→ focus-tree listeners →TermControl) and setsControlKeyStates::EnhancedKeyinTermControl, matching the regular key path.References and Relevant Issues
Closes #18120
Validation Steps Performed
Full local build:
CascadiaPackagebuilt locally (x64 Release, VS 2026 / SDK 10.0.26100), registered withAdd-AppxPackage -Registerand run on Windows 11.Live repro validation: ran the
ReadConsoleInputWsample from #18120 inside the locally built terminal and pressed/released RightAlt (extended) and LeftAlt (non-extended):Before this change the RightAlt release line reported
ENHANCED_KEY: 0(per the issue). Screen recording of the locally built terminal running the repro:Screenshot: validation-screenshot.png · Raw log: keyrepro.log · Repro source: keyrepro.cpp
Unit test: new
InputTest::Win32KeyEventsRetainEnhancedKeyinUnitTests_TerminalCoreverifies win32-input-mode encodesENHANCED_KEYin theCsparameter for both press (Cs=257) and release (Cs=256) of RightAlt viaTerminal::SendKeyEvent. Passes locally via TAEF (x64 Release), together with the pre-existingInputTestmethods.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