aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/winpty/misc/VkEscapeTest.cc
blob: 97bf59f998ba319cd5ac3152ce543785af0f6172 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Sending VK_PAUSE to the console window almost works as a mechanism for
 * pausing it, but it doesn't because the console could turn off the
 * ENABLE_LINE_INPUT console mode flag.
 */

#define _WIN32_WINNT 0x0501
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

CALLBACK DWORD pausingThread(LPVOID dummy)
{
    if (1) {
        Sleep(1000);
        HWND hwnd = GetConsoleWindow();
        SendMessage(hwnd, WM_KEYDOWN, VK_PAUSE, 1);
        Sleep(1000);
        SendMessage(hwnd, WM_KEYDOWN, VK_ESCAPE, 1);
    }

    if (0) {
        INPUT_RECORD ir;
        memset(&ir, 0, sizeof(ir));
        ir.EventType = KEY_EVENT;
        ir.Event.KeyEvent.bKeyDown = TRUE;
        ir.Event.KeyEvent.wVirtualKeyCode = VK_PAUSE;
        ir.Event.KeyEvent.wRepeatCount = 1;
    }

    return 0;
}

int main()
{
    HANDLE hin = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD c = { 0, 0 };

    DWORD mode;
    GetConsoleMode(hin, &mode);
    SetConsoleMode(hin, mode &
                   ~(ENABLE_LINE_INPUT));

    CreateThread(NULL, 0,
                 pausingThread, NULL,
                 0, NULL);

    int i = 0;
    while (true) {
        Sleep(100);
        printf("%d\n", ++i);
    }

    return 0;
}