Created
March 6, 2020 09:01
-
-
Save srayuws/b2ad70d719a0963b93bdd94e5eac888d to your computer and use it in GitHub Desktop.
Code to reproduce.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
int main() | |
{ | |
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);; | |
INPUT_RECORD irInBuf[128]; | |
DWORD i,cNumRead; | |
bool exit = false; | |
printf("Try to press some key\n"); | |
while (!exit) { | |
ReadConsoleInput(hStdin, irInBuf, 128, &cNumRead); | |
for (i = 0; i < cNumRead; i++) { | |
switch (irInBuf[i].EventType) | |
{ | |
case KEY_EVENT: // keyboard input | |
KEY_EVENT_RECORD keyEvent = irInBuf[i].Event.KeyEvent; | |
if (keyEvent.bKeyDown) { | |
printf("KEY_EVENT_RECORD: \n"); | |
printf("\twRepeatCount: 0x%x\n", keyEvent.wRepeatCount); | |
printf("\twVirtualKeyCode: 0x%x\n",keyEvent.wVirtualKeyCode); | |
printf("\twVirtualScanCode: 0x%x\n",keyEvent.wVirtualScanCode); | |
printf("\tuChar.UnicodeChar: 0x%x\n",keyEvent.uChar.UnicodeChar); | |
printf("\tuChar.AsciiChar: 0x%x\n",keyEvent.uChar.AsciiChar); | |
printf("\tdwControlKeyState: 0x%x\n",keyEvent.dwControlKeyState); | |
printf("\n"); | |
} | |
if (keyEvent.wVirtualKeyCode == 0x51) { // press Q to exit | |
exit = true; | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment