Home | History | Annotate | Download | only in common
      1 /*
      2  $License:
      3     Copyright (C) 2012 InvenSense Corporation, All Rights Reserved.
      4  $
      5  */
      6 
      7 /******************************************************************************
      8  *
      9  * $Id:$
     10  *
     11  *****************************************************************************/
     12 
     13 #include <stdio.h>
     14 #ifdef _WIN32
     15 #include <windows.h>
     16 #include <conio.h>
     17 #endif
     18 #ifdef LINUX
     19 #include <sys/select.h>
     20 #endif
     21 #include <time.h>
     22 #include <string.h>
     23 
     24 int ConsoleKbhit(void)
     25 {
     26 #ifdef _WIN32
     27     return _kbhit();
     28 #else
     29     struct timeval tv;
     30     fd_set read_fd;
     31 
     32     tv.tv_sec=0;
     33     tv.tv_usec=0;
     34     FD_ZERO(&read_fd);
     35     FD_SET(0, &read_fd);
     36 
     37     if(select(1, &read_fd, NULL, NULL, &tv) == -1)
     38         return 0;
     39 
     40     if(FD_ISSET(0, &read_fd))
     41         return 1;
     42 
     43     return 0;
     44 #endif
     45 }
     46 
     47 char ConsoleGetChar(void)
     48 {
     49 #ifdef _WIN32
     50     return _getch();
     51 #else
     52     return getchar();
     53 #endif
     54 }
     55