ENHANCED_KEY flag missing when releasing RightAlt #22464

Open
opened 2026-01-31 08:14:08 +00:00 by claunia · 1 comment
Owner

Originally created by @o-sdn-o on GitHub (Oct 28, 2024).

Windows Terminal version

current main

Windows build number

10.0.19045.4894

Other Software

No response

Steps to reproduce

  1. Run the following c++ code:
#include <iostream>
#include <windows.h>
int main()
{
    INPUT_RECORD rec;
    DWORD count;
    while (true)
    {
        ::ReadConsoleInputW(::GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &count);
        if (rec.EventType == KEY_EVENT)
        {
            std::cout << "type: KEY_EVENT" << std::hex
                      << ", down: " << rec.Event.KeyEvent.bKeyDown
                      << ", ENHANCED_KEY: " << !!(rec.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY)
                      << ", ctrl: 0x" << rec.Event.KeyEvent.dwControlKeyState
                      << ", vcod: 0x" << rec.Event.KeyEvent.wVirtualKeyCode
                      << ", scod: 0x" << rec.Event.KeyEvent.wVirtualScanCode
                      << ", wchr: 0x" << rec.Event.KeyEvent.uChar.UnicodeChar << '\n';
        }
    }
}
  1. Press LeftCtrl key, press RightCtrl key, check ENHANCED_KEY flag.
  2. Press LeftAlt key, press RightAlt key, check ENHANCED_KEY flag.

Expected Behavior

The ENHANCED_KEY flag is present when RightAlt is pressed and released.

The current conhost.exe is not affected by this issue.

Actual Behavior

The ENHANCED_KEY flag is absent when RightAlt is released, but is present when RightAlt is pressed.

Originally created by @o-sdn-o on GitHub (Oct 28, 2024). ### Windows Terminal version current main ### Windows build number 10.0.19045.4894 ### Other Software _No response_ ### Steps to reproduce 1. Run the following c++ code: ```c++ #include <iostream> #include <windows.h> int main() { INPUT_RECORD rec; DWORD count; while (true) { ::ReadConsoleInputW(::GetStdHandle(STD_INPUT_HANDLE), &rec, 1, &count); if (rec.EventType == KEY_EVENT) { std::cout << "type: KEY_EVENT" << std::hex << ", down: " << rec.Event.KeyEvent.bKeyDown << ", ENHANCED_KEY: " << !!(rec.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY) << ", ctrl: 0x" << rec.Event.KeyEvent.dwControlKeyState << ", vcod: 0x" << rec.Event.KeyEvent.wVirtualKeyCode << ", scod: 0x" << rec.Event.KeyEvent.wVirtualScanCode << ", wchr: 0x" << rec.Event.KeyEvent.uChar.UnicodeChar << '\n'; } } } ``` 2. Press LeftCtrl key, press RightCtrl key, check ENHANCED_KEY flag. 3. Press LeftAlt key, press RightAlt key, check ENHANCED_KEY flag. ### Expected Behavior The ENHANCED_KEY flag is present when RightAlt is pressed and released. The current conhost.exe is not affected by this issue. ### Actual Behavior The ENHANCED_KEY flag is absent when RightAlt is released, but is present when RightAlt is pressed.
claunia added the Help WantedIssue-BugArea-InputProduct-Terminal labels 2026-01-31 08:14:08 +00:00
Author
Owner

@o-sdn-o commented on GitHub (Oct 29, 2024):

It might be located here, when manually sending an Alt key release:

8d3f12b1c0/src/cascadia/WindowsTerminal/WindowThread.cpp (L223-L234)

The subsequent call to _GetPressedModifierKeys() does not return any pressed Alt keys, so the extended key flag is lost:

8d3f12b1c0/src/cascadia/TerminalControl/TermControl.cpp (L1466-L1475)

The solution is to take the ENHANCED_KEY flag from lParam (24th bit) of the WM_KEYUP message.

@o-sdn-o commented on GitHub (Oct 29, 2024): It might be located here, when manually sending an Alt key release: https://github.com/microsoft/terminal/blob/8d3f12b1c065a965974cd6b5bc7a81176ffb0f1b/src/cascadia/WindowsTerminal/WindowThread.cpp#L223-L234 The subsequent call to _GetPressedModifierKeys() does not return any pressed Alt keys, so the extended key flag is lost: https://github.com/microsoft/terminal/blob/8d3f12b1c065a965974cd6b5bc7a81176ffb0f1b/src/cascadia/TerminalControl/TermControl.cpp#L1466-L1475 The solution is to take the ENHANCED_KEY flag from lParam (24th bit) of the [WM_KEYUP message](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keyup).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22464