2011-11-24 11:03:05 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
2012-01-21 10:31:27 +00:00
|
|
|
#include <ctype.h>
|
2011-11-24 11:03:05 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-03-20 04:13:10 +00:00
|
|
|
static int escCount = 0;
|
|
|
|
|
2011-11-24 11:03:05 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-03-20 04:13:10 +00:00
|
|
|
|
|
|
|
if (true) {
|
|
|
|
DWORD mode;
|
|
|
|
GetConsoleMode(hStdin, &mode);
|
|
|
|
SetConsoleMode(hStdin, mode & ~ENABLE_PROCESSED_INPUT);
|
|
|
|
}
|
|
|
|
|
2011-11-24 11:03:05 +00:00
|
|
|
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);
|
2012-03-20 04:13:10 +00:00
|
|
|
printf(" vk=%#x", ker.wVirtualKeyCode);
|
|
|
|
printf(" scan=%#x", ker.wVirtualScanCode);
|
|
|
|
printf(" state=%#x", (int)ker.dwControlKeyState);
|
2011-11-24 11:03:05 +00:00
|
|
|
printf(" repeat=%d", ker.wRepeatCount);
|
|
|
|
printf("\n");
|
2012-03-20 04:13:10 +00:00
|
|
|
if (ker.uChar.AsciiChar == 27 && ++escCount == 6)
|
|
|
|
break;
|
2011-11-24 11:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|