#include #include #include #include #include #include #include #include #include int kbhit1( int stdfd ); int main() { char c; int stdfd; struct termios oldtio, newtio; stdfd = fileno(stdin); printf("----\n"); while(1) { printf( "%x", c = kbhit1( stdfd ) ); //printf( "%x", c = getchar() ); } return 0; } int kbhit1( int stdfd ) { fd_set readfs; struct timeval Timeout; unsigned char rv; int res; while(1) { printf(" loop working \n"); FD_SET(stdfd, &readfs); Timeout.tv_sec = 3; printf( "select:%d", res = select(stdfd + 1, &readfs, NULL, NULL, &Timeout)); if ( res < 0 ) { perror(" Error on the select"); return -1; } else if ( res > 0 ) { if ( FD_ISSET(stdfd,&readfs) ) { if ( read(stdfd,&rv,1) < 0 ) { perror( "Error on read" ); return -1; } return rv; } else return 0; } } }