Browse Source

Implement conio.h's kbhit().

tags/v0.99.beta17
Sam Hocevar sam 15 years ago
parent
commit
962f47b906
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      caca/caca_conio.c

+ 17
- 10
caca/caca_conio.c View File

@@ -32,6 +32,7 @@ static caca_canvas_t *cv;
static caca_display_t *dp; static caca_display_t *dp;


static int unget_ch = -1; static int unget_ch = -1;
static int kbhit_ch = -1;
static char pass_buffer[BUFSIZ]; static char pass_buffer[BUFSIZ];
static char cgets_buffer[BUFSIZ]; static char cgets_buffer[BUFSIZ];


@@ -126,7 +127,6 @@ void caca_conio_delline(void)
int caca_conio_getch(void) int caca_conio_getch(void)
{ {
caca_event_t ev; caca_event_t ev;
int ch;


conio_init(); conio_init();


@@ -137,17 +137,15 @@ int caca_conio_getch(void)
return tmp; return tmp;
} }


caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
ch = caca_get_event_key_ch(&ev);

switch(ch)
if(kbhit_ch >= 0)
{ {
case CACA_KEY_LEFT: ch = 75; break;
case CACA_KEY_RIGHT: ch = 77; break;
default: break;
int tmp = kbhit_ch;
kbhit_ch = -1;
return tmp;
} }


return ch;
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
return caca_get_event_key_ch(&ev);
} }


/** \brief DOS conio.h getche() equivalent */ /** \brief DOS conio.h getche() equivalent */
@@ -218,9 +216,18 @@ void caca_conio_insline(void)
/** \brief DOS conio.h kbhit() equivalent */ /** \brief DOS conio.h kbhit() equivalent */
int caca_conio_kbhit(void) int caca_conio_kbhit(void)
{ {
caca_event_t ev;

conio_init(); conio_init();


/* TODO: implement this function */
if(kbhit_ch >= 0)
return 1;

if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{
kbhit_ch = caca_get_event_key_ch(&ev);
return 1;
}


return 0; return 0;
} }


Loading…
Cancel
Save