_WCRTLINK int kbhit( void ) { DWORD n; HANDLE h; INPUT_RECORD r; #ifdef DEFAULT_WINDOWING if( _WindowsKbhit != 0 ) { LPWDATA res; res = _WindowsIsWindowedHandle( (int) STDIN_FILENO ); return( _WindowsKbhit( res ) ); } #endif _AccessFileH( STDIN_FILENO ); h = __NTConsoleInput(); for(;;) { PeekConsoleInput( h, &r, 1, &n ); if( n == 0 ) break; if( __NTRealKey( &r ) ) break; // flush out mouse, window, and key up events ReadConsoleInput( h, &r, 1, &n ); } // n != 0 if there is a key waiting _ReleaseFileH( STDIN_FILENO ); return( n != 0 ); }
_WCRTLINK int kbhit( void ) { KBDKEYINFO info; if( _RWD_cbyte != 0 ) return( 1 ); #ifdef DEFAULT_WINDOWING if( _WindowsKbhit != NULL ) { // Default windowing LPWDATA res; res = _WindowsIsWindowedHandle( (int) STDIN_FILENO ); return( _WindowsKbhit( res ) ); } #endif #if defined(__OS2_286__) if( _RWD_osmode == DOS_MODE ) { return( _os_kbhit() ); } KbdPeek( &info, 0 ); return( ( info.fbStatus & 0xe0 ) != 0 ); #else KbdPeek( &info, 0 ); return( ( info.fbStatus & 0xe0 ) != 0 ); #endif }