-int input_available() {
-
- static HANDLE inh = NULL;
- static bool usePipe = false;
- INPUT_RECORD rec[256];
- DWORD nchars, recCnt;
-
- if (!inh)
- {
- inh = GetStdHandle(STD_INPUT_HANDLE);
- if (GetConsoleMode(inh, &nchars))
- {
- SetConsoleMode(inh, nchars & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
- FlushConsoleInputBuffer(inh);
- } else
- usePipe = true;
- }
-
- // When using Standard C input functions, also check if there
- // is anything in the buffer. After a call to such functions,
- // the input waiting in the pipe will be copied to the buffer,
- // and the call to PeekNamedPipe can indicate no input available.
- // Setting stdin to unbuffered was not enough. [from Greko]
- if (stdin->_cnt > 0)
- return 1;