aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/winpty/misc/ShowConsoleInput.cc
blob: 75fbfb81f10715795423d1e99eb58ee5309c4bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <windows.h>
#include <stdio.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    static int escCount = 0;

    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    while (true) {
        DWORD count;
        INPUT_RECORD ir;
        if (!ReadConsoleInput(hStdin, &ir, 1, &count)) {
            printf("ReadConsoleInput failed\n");
            return 1;
        }

        if (true) {
            DWORD mode;
            GetConsoleMode(hStdin, &mode);
            SetConsoleMode(hStdin, mode & ~ENABLE_PROCESSED_INPUT);
        }

        if (ir.EventType == KEY_EVENT) {
            const KEY_EVENT_RECORD &ker = ir.Event.KeyEvent;
            printf("%s", ker.bKeyDown ? "dn" : "up");
            printf(" ch=");
            if (isprint(ker.uChar.AsciiChar))
                printf("'%c'", ker.uChar.AsciiChar);
            printf("%d", ker.uChar.AsciiChar);
            printf(" vk=%#x", ker.wVirtualKeyCode);
            printf(" scan=%#x", ker.wVirtualScanCode);
            printf(" state=%#x", (int)ker.dwControlKeyState);
            printf(" repeat=%d", ker.wRepeatCount);
            printf("\n");
            if (ker.uChar.AsciiChar == 27 && ++escCount == 6)
                break;
        }
    }
}