Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENHANCED_KEY flag missing when releasing RightAlt #18120

Open
o-sdn-o opened this issue Oct 28, 2024 · 1 comment
Open

ENHANCED_KEY flag missing when releasing RightAlt #18120

o-sdn-o opened this issue Oct 28, 2024 · 1 comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Milestone

Comments

@o-sdn-o
Copy link

o-sdn-o commented 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.

@o-sdn-o o-sdn-o added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 28, 2024
@o-sdn-o
Copy link
Author

o-sdn-o commented Oct 29, 2024

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

// GH#6421 - System XAML will never send an Alt KeyUp event. So, similar
// to how we'll steal the F7 KeyDown above, we'll steal the Alt KeyUp
// here, and plumb it through.
if (_messageIsAltKeyup(message))
{
// Let's pass <Alt> to the application
if (_host->OnDirectKeyEvent(VK_MENU, LOBYTE(HIWORD(message.lParam)), false))
{
// The application consumed the Alt. Don't let Xaml get it.
continue;
}
}

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

// Method Description:
// - Manually handles key events for certain keys that can't be passed to us
// normally. Namely, the keys we're concerned with are F7 down and Alt up.
// Return value:
// - Whether the key was handled.
bool TermControl::OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down)
{
const auto modifiers{ _GetPressedModifierKeys() };
return _KeyHandler(gsl::narrow_cast<WORD>(vkey), gsl::narrow_cast<WORD>(scanCode), modifiers, down);
}

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

@carlos-zamora carlos-zamora added Area-Input Related to input processing (key presses, mouse, etc.) Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Oct 30, 2024
@carlos-zamora carlos-zamora added this to the Backlog milestone Oct 30, 2024
@carlos-zamora carlos-zamora added the Help Wanted We encourage anyone to jump in on these. label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

No branches or pull requests

2 participants