Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <sys/time.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5.  
  6. #define STDIN 0
  7.  
  8. int main(void)
  9.     {
  10.     struct timeval tv;
  11.     fd_set readfds;
  12.  
  13.     tv.tv_sec  = 2;
  14.     tv.tv_usec = 500000;
  15.  
  16.     FD_ZERO(&readfds);
  17.     FD_SET(STDIN, &readfds);
  18.  
  19.     select(STDIN+1, &readfds, NULL, NULL, &tv);
  20.  
  21.     if (FD_ISSET(STDIN, &readfds))
  22.         printf("A key was pressed!\n");
  23.     else
  24.         printf("Timed out.\n");
  25.  
  26.     return 0;
  27.     }