getChar() is very similar, except that it uses ReadConsole() to actually read a character from the console input buffer.Code:bool keyHit(void) { /* Get a handle to console input buffer */ HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE); /* Save the console mode so we can restore it later */ DWORD saveMode; GetConsoleMode(stdIn, &saveMode); /* Set the console mode. The primary purpose of this is * to make sure ENABLE_LINE_INPUT is disabled. As its name * suggests ENABLE_LINE_INPUT will not return until the end of * the line while we are interested in individual characters. */ SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT); bool ret = false; /* This waits 1 millisecond for the input buffer to be signalled * The input buffer enters the signalled state when one or more characters * are available. If the input buffer is signalled WaitForSingleObject() * will return WAIT_OBJECT_0 and we set ret to true to indicate that there * is character(s) in the input buffer. If the input buffer does not become * signalled in the timeout period it will return WAIT_TIMEOUT. */ if (WaitForSingleObject(stdIn, 1) == WAIT_OBJECT_0) ret = true; /* We restore the console mode that we saved at the start of the function. */ SetConsoleMode(stdIn, saveMode); /* We return the value of ret */ return(ret); }