static int kbhit(void){ struct timeval timeout; fd_set read_handles; int status; // check stdin (fd 0) for activity FD_ZERO(&read_handles); FD_SET(0, &read_handles); timeout.tv_sec = timeout.tv_usec = 0; status = select(0 + 1, &read_handles, NULL, NULL, &timeout); return status; }