| 1 |
#include <windows.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <ctype.h> |
| 4 |
|
| 5 |
int main(int argc, char *argv[]) |
| 6 |
{ |
| 7 |
static int escCount = 0; |
| 8 |
|
| 9 |
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); |
| 10 |
while (true) { |
| 11 |
DWORD count; |
| 12 |
INPUT_RECORD ir; |
| 13 |
if (!ReadConsoleInput(hStdin, &ir, 1, &count)) { |
| 14 |
printf("ReadConsoleInput failed\n"); |
| 15 |
return 1; |
| 16 |
} |
| 17 |
|
| 18 |
if (true) { |
| 19 |
DWORD mode; |
| 20 |
GetConsoleMode(hStdin, &mode); |
| 21 |
SetConsoleMode(hStdin, mode & ~ENABLE_PROCESSED_INPUT); |
| 22 |
} |
| 23 |
|
| 24 |
if (ir.EventType == KEY_EVENT) { |
| 25 |
const KEY_EVENT_RECORD &ker = ir.Event.KeyEvent; |
| 26 |
printf("%s", ker.bKeyDown ? "dn" : "up"); |
| 27 |
printf(" ch="); |
| 28 |
if (isprint(ker.uChar.AsciiChar)) |
| 29 |
printf("'%c'", ker.uChar.AsciiChar); |
| 30 |
printf("%d", ker.uChar.AsciiChar); |
| 31 |
printf(" vk=%#x", ker.wVirtualKeyCode); |
| 32 |
printf(" scan=%#x", ker.wVirtualScanCode); |
| 33 |
printf(" state=%#x", (int)ker.dwControlKeyState); |
| 34 |
printf(" repeat=%d", ker.wRepeatCount); |
| 35 |
printf("\n"); |
| 36 |
if (ker.uChar.AsciiChar == 27 && ++escCount == 6) |
| 37 |
break; |
| 38 |
} |
| 39 |
} |
| 40 |
} |