Man kunne kaste sig ud i:
#include <iostream>
#include <windows.h>
WORD Read(HANDLE StdIn)
{
DWORD NumEvents;
GetNumberOfConsoleInputEvents(StdIn, &NumEvents);
if(NumEvents)
{
INPUT_RECORD Record;
DWORD NumRead;
ReadConsoleInput(StdIn, &Record, 1, &NumRead);
if(Record.EventType & KEY_EVENT && Record.Event.KeyEvent.bKeyDown)
return Record.Event.KeyEvent.wVirtualKeyCode;
}
return 0;
}
int main()
{
HANDLE StdIn = GetStdHandle(STD_INPUT_HANDLE);
SetConsoleMode(StdIn, ENABLE_PROCESSED_INPUT);
while(1)
{
switch(WaitForSingleObject(StdIn, 1000))
{
case WAIT_OBJECT_0:
{
char Key = (char )Read(StdIn);
if(Key)
std::cout << "Key: " << Key << std::endl;
}
break;
case WAIT_TIMEOUT:
std::cout << "Timeout" << std::endl;
break;
case WAIT_ABANDONED:
std::cout << "Fatal error, exiting" << std::endl;
return 0;
}
}
}