Re: WaitForSingleObject on Console not working???
How can I know if there is input or not from keyboard in console
application? I want to flush buffer to screen every second.
In Unix, select( ) with stdin and timeout can work well( return timeout
every second ), but in Windows, stdin is NOTSOCK, hence select won't
In Windows, WaitForSingleObject( stdinHandle, 1000 ) will return
"WAIT_OBJECT_0" when waiting for input.
How come the following always goes into "WAIT_OBJECT_0"?
Because there is some input on the handle at startup (probably a
FOCUS_EVENT_RECORD), and until you read that, wait calls will return
What could I do? Is there any way to use select( ) in Windows with
Try playing with this:
static HANDLE stdinHandle;
// Get the IO handles
stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
DWORD rc = WaitForSingleObject(stdinHandle, 1000);
if( rc == WAIT_TIMEOUT )
else if( rc == WAIT_ABANDONED )
else if( rc == WAIT_OBJECT_0 )
ReadConsoleInput(stdinHandle, r, 512, &read);
printf("Read: %d", read);
else if( rc == WAIT_FAILED )