microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.87k stars 8.34k forks source link

Releasing both pressed Shift keys (left+right) reports only one #18223

Open o-sdn-o opened 6 days ago

o-sdn-o commented 6 days ago

Windows Terminal version

current main

Windows build number

10.0.19045.5011

Other Software

No response

Steps to reproduce

  1. Activate "debug tap" pane.
    • Add the global setting (near the top of your JSON file):
      "debugFeatures": true
    • Open a new tab while holding down both left and right Alt .
  2. Press and release both Shift keys simultaneously.

Expected Behavior

There are four reports in the "debug tap" pane:

Actual Behavior

Image

There are only three reports in the "debug tap" pane:

o-sdn-o commented 6 days ago

Since the operating system (at least 10.0.19045.5011) does not generate a right Shift key release WM_KEYUP event after detecting a second Shift key pressed, the possible solution is to use a timer to track the right Shift key down state in the thread's keyboard buffer. This works reliably with a 33ms tick timer.

carlos-zamora commented 6 days ago

Thanks for filing! Does this repro in conhost /?

o-sdn-o commented 6 days ago

Does this repro in conhost /?

Yes, this issue is also reproduced in conhost.

#include <iostream>
#include <windows.h>

int main()
{
    DWORD count;
    INPUT_RECORD r;
    HANDLE input = ::GetStdHandle(STD_INPUT_HANDLE);
    while (true)
    {
        ::ReadConsoleInputW(input, &r, 1, &count);
        if (r.EventType == KEY_EVENT)
        {
            std::cout << "type: KEY_EVENT" << std::hex
                << ", down: " << r.Event.KeyEvent.bKeyDown
                << ", ctrl: " << r.Event.KeyEvent.dwControlKeyState
                << ", count: " << r.Event.KeyEvent.wRepeatCount
                << ", vcod: " << r.Event.KeyEvent.wVirtualKeyCode
                << ", scod: " << r.Event.KeyEvent.wVirtualScanCode
                << ", wchr: " << (int)r.Event.KeyEvent.uChar.UnicodeChar << '\n';
        }
    }
}

Image