Changeset 3594


Ignore:
Timestamp:
07/31/09 02:01:13 (4 years ago)
Author:
sam
Message:

Implement conio.h's kbhit().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/caca_conio.c

    r3592 r3594  
    3333 
    3434static int unget_ch = -1; 
     35static int kbhit_ch = -1; 
    3536static char pass_buffer[BUFSIZ]; 
    3637static char cgets_buffer[BUFSIZ]; 
     
    127128{ 
    128129    caca_event_t ev; 
    129     int ch; 
    130130 
    131131    conio_init(); 
     
    138138    } 
    139139 
     140    if(kbhit_ch >= 0) 
     141    { 
     142        int tmp = kbhit_ch; 
     143        kbhit_ch = -1; 
     144        return tmp; 
     145    } 
     146 
    140147    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); 
    141     ch = caca_get_event_key_ch(&ev); 
    142  
    143     switch(ch) 
    144     { 
    145         case CACA_KEY_LEFT: ch = 75; break; 
    146         case CACA_KEY_RIGHT: ch = 77; break; 
    147         default: break; 
    148     } 
    149  
    150     return ch; 
     148    return caca_get_event_key_ch(&ev); 
    151149} 
    152150 
     
    219217int caca_conio_kbhit(void) 
    220218{ 
    221     conio_init(); 
    222  
    223     /* TODO: implement this function */ 
     219    caca_event_t ev; 
     220 
     221    conio_init(); 
     222 
     223    if(kbhit_ch >= 0) 
     224        return 1; 
     225 
     226    if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0)) 
     227    { 
     228        kbhit_ch = caca_get_event_key_ch(&ev); 
     229        return 1; 
     230    } 
    224231 
    225232    return 0; 
Note: See TracChangeset for help on using the changeset viewer.