src/keyboard.c
changeset 0 06dd3b8d90ad
equal deleted inserted replaced
-1:000000000000 0:06dd3b8d90ad
       
     1 /**
       
     2  *  $Id: keyboard.c 53 2008-01-10 00:19:41Z mbroeker $
       
     3  * $URL: http://localhost/svn/c/VirtualReader/trunk/src/keyboard.c $
       
     4  */
       
     5 
       
     6 #include <keyboard.h>
       
     7 
       
     8 char getSingleKey ()
       
     9 {
       
    10     // read and return single key with 1 second timeout
       
    11 
       
    12     struct termios new_settings;
       
    13     struct termios stored_settings;
       
    14     int timeout = 1;            // 1 sec timeout
       
    15     char c;
       
    16 
       
    17     tcgetattr (0, &stored_settings);
       
    18     new_settings = stored_settings;
       
    19 
       
    20     new_settings.c_lflag &= ~(ICANON | ECHO);
       
    21 
       
    22     new_settings.c_cc[VTIME] = timeout * 10;
       
    23     new_settings.c_cc[VMIN] = 0;
       
    24     tcsetattr (0, TCSANOW, &new_settings);
       
    25 
       
    26     fflush (stdout);
       
    27     c = getchar ();
       
    28 
       
    29     tcsetattr (0, TCSANOW, &stored_settings);
       
    30 
       
    31 #ifdef DEBUG
       
    32     if (isalpha (c))
       
    33         printf ("received keypress: %c\n", c);
       
    34 #endif
       
    35     return c;
       
    36 }