Win32 input make/break events are generated at the same time #11630

Open
opened 2026-01-31 02:52:58 +00:00 by claunia · 0 comments
Owner

Originally created by @o-sdn-o on GitHub (Nov 29, 2020).

Environment

Windows build number: 10.0.19041.572
Windows Terminal version (if applicable): master

In the classic windows console, you can track alphanumeric key combinations (for example, tracking the keys w, a, s, d simultaneously). This tracking cannot be done in Windows Terminal.

Steps to reproduce

Run the following code
Press a couple of alphanumeric keys at the same time, e.g. q+w+e

#include <iostream>
#include <unordered_set>
#include <Windows.h>

int main()
{
    DWORD                    Count;
    INPUT_RECORD             Reply;
    std::unordered_set<WORD> State;

    auto Input = GetStdHandle(STD_INPUT_HANDLE);

    while (WAIT_OBJECT_0 == WaitForSingleObject(Input, INFINITE))
    {
        ReadConsoleInput(Input, &Reply, 1, &Count);
        switch (Reply.EventType)
        {
            case KEY_EVENT:
            {
                //std::cout
                //    << " Down: "     << Reply.Event.KeyEvent.bKeyDown
                //    << " Repeat: "   << Reply.Event.KeyEvent.wRepeatCount
                //    << " KeyCode: "  << Reply.Event.KeyEvent.wVirtualKeyCode
                //    << " ScanCode: " << Reply.Event.KeyEvent.wVirtualScanCode
                //    << " Char: "     << Reply.Event.KeyEvent.uChar.UnicodeChar
                //    << " KeyState: " << Reply.Event.KeyEvent.dwControlKeyState
                //    << std::endl << std::flush;

                auto ScanCode = Reply.Event.KeyEvent.wVirtualScanCode;
                auto KeyDown = Reply.Event.KeyEvent.bKeyDown;
                auto Changed = KeyDown ? State.emplace(ScanCode).second
                                       : State.erase(ScanCode);
                if (Changed)
                {
                    std::cout << "chord:";
                    for (auto Key : State) std::cout << " " << Key;
                    std::cout << std::endl << std::flush;
                }
                break;
            }
            default:
                break;
        }
    }
}

Expected behavior

Key combinations are tracked (classic console behavior)

D:\sources\temp\ConsoleApplication1\Debug>ConsoleApplication1.exe
chord: 16
chord: 16 17
chord: 16 17 18
chord: 16 17
chord: 16
chord:
chord: 16
chord: 16 17
chord: 16 17 18
chord: 17 18
chord: 18
chord:

Actual behavior

Single keystrokes are tracked only (Windows Terminal behavior)

D:\sources\temp\ConsoleApplication1\Debug>ConsoleApplication1.exe
chord: 16
chord:
chord: 17
chord:
chord: 18
chord:
chord: 18
chord:
chord: 18
chord:
chord: 18
chord:
chord: 18
chord:
...
Originally created by @o-sdn-o on GitHub (Nov 29, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.19041.572 Windows Terminal version (if applicable): master ``` In the classic windows console, you can track alphanumeric key combinations (for example, tracking the keys <kbd>w</kbd>, <kbd>a</kbd>, <kbd>s</kbd>, <kbd>d</kbd> simultaneously). This tracking cannot be done in Windows Terminal. # Steps to reproduce Run the following code Press a couple of alphanumeric keys at the same time, e.g. <kbd>q</kbd>+<kbd>w</kbd>+<kbd>e</kbd> ```c++ #include <iostream> #include <unordered_set> #include <Windows.h> int main() { DWORD Count; INPUT_RECORD Reply; std::unordered_set<WORD> State; auto Input = GetStdHandle(STD_INPUT_HANDLE); while (WAIT_OBJECT_0 == WaitForSingleObject(Input, INFINITE)) { ReadConsoleInput(Input, &Reply, 1, &Count); switch (Reply.EventType) { case KEY_EVENT: { //std::cout // << " Down: " << Reply.Event.KeyEvent.bKeyDown // << " Repeat: " << Reply.Event.KeyEvent.wRepeatCount // << " KeyCode: " << Reply.Event.KeyEvent.wVirtualKeyCode // << " ScanCode: " << Reply.Event.KeyEvent.wVirtualScanCode // << " Char: " << Reply.Event.KeyEvent.uChar.UnicodeChar // << " KeyState: " << Reply.Event.KeyEvent.dwControlKeyState // << std::endl << std::flush; auto ScanCode = Reply.Event.KeyEvent.wVirtualScanCode; auto KeyDown = Reply.Event.KeyEvent.bKeyDown; auto Changed = KeyDown ? State.emplace(ScanCode).second : State.erase(ScanCode); if (Changed) { std::cout << "chord:"; for (auto Key : State) std::cout << " " << Key; std::cout << std::endl << std::flush; } break; } default: break; } } } ``` # Expected behavior Key combinations are tracked (classic console behavior) ``` D:\sources\temp\ConsoleApplication1\Debug>ConsoleApplication1.exe chord: 16 chord: 16 17 chord: 16 17 18 chord: 16 17 chord: 16 chord: chord: 16 chord: 16 17 chord: 16 17 18 chord: 17 18 chord: 18 chord: ``` # Actual behavior Single keystrokes are tracked only (Windows Terminal behavior) ``` D:\sources\temp\ConsoleApplication1\Debug>ConsoleApplication1.exe chord: 16 chord: chord: 17 chord: chord: 18 chord: chord: 18 chord: chord: 18 chord: chord: 18 chord: chord: 18 chord: ... ```
claunia added the Issue-BugIssue-TaskIn-PRArea-InputNeeds-Tag-FixProduct-Terminal labels 2026-01-31 02:52:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#11630