nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include "keyb.h" nuclear@0: nuclear@0: int main(void) nuclear@0: { nuclear@0: int key; nuclear@0: nuclear@0: /* The argument to kb_init specifies how many keypresses to buffer up. nuclear@0: * If you don't need any keypress buffering, pass 0 to disable it. nuclear@0: */ nuclear@0: kb_init(16); nuclear@0: nuclear@2: printf("Press any key to continue ...\n"); nuclear@2: nuclear@2: /* example of active polling... The same can be done better by using nuclear@2: * kb_wait() nuclear@2: */ nuclear@2: while(!kb_isdown(KB_ANY)); nuclear@2: kb_getkey(); /* discard the key we just detected */ nuclear@2: nuclear@2: printf("Key tester, quit by pressing esc\n"); nuclear@0: for(;;) { nuclear@0: kb_wait(); /* wait for any keypress */ nuclear@0: key = kb_getkey(); /* get the pressed key */ nuclear@0: assert(key != -1); /* this should never happen since kb_wait returned */ nuclear@0: nuclear@0: if(key == 27) break; /* quit on esc */ nuclear@0: nuclear@0: /* if it's a printable character print it along with the key value */ nuclear@0: if(isprint(key)) { nuclear@0: printf("key: %d '%c'\n", key, (char)key); nuclear@0: } else { nuclear@0: printf("key: %d\n", key); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: kb_shutdown(); nuclear@0: return 0; nuclear@0: }