/********************************************************************* * _kbhit (MSVCRT.@) */ int CDECL _kbhit(void) { int retval = 0; LOCK_CONSOLE; if (__MSVCRT_console_buffer != MSVCRT_EOF) retval = 1; else { /* FIXME: There has to be a faster way than this in Win32.. */ INPUT_RECORD *ir = NULL; DWORD count = 0, i; GetNumberOfConsoleInputEvents(MSVCRT_console_in, &count); if (count && (ir = MSVCRT_malloc(count * sizeof(INPUT_RECORD))) && PeekConsoleInputA(MSVCRT_console_in, ir, count, &count)) for(i = 0; i < count - 1; i++) { if (ir[i].EventType == KEY_EVENT && ir[i].Event.KeyEvent.bKeyDown && ir[i].Event.KeyEvent.uChar.AsciiChar) { retval = 1; break; } } MSVCRT_free(ir); } UNLOCK_CONSOLE; return retval; }
int n, icount, total; // how many events are there? if(!GetNumberOfConsoleInputEvents(pipe, &count)) return -1; // peek them all rec = (INPUT_RECORD *)malloc(count * sizeof(INPUT_RECORD)); BOOL ret; #if QT_VERSION >= 0x050000 ret = PeekConsoleInputW(pipe, rec, count, &i); #else QT_WA( ret = PeekConsoleInputW(pipe, rec, count, &i); , ret = PeekConsoleInputA(pipe, rec, count, &i); ) #endif if(!ret) { free(rec); return -1; } icount = pipe_dword_cap_to_int(i); // process only the amount returned // see which ones are normal keypress events total = 0; for(n = 0; n < icount; ++n) { if(rec[n].EventType == KEY_EVENT)