doskeyb

view test.c @ 2:da4c014bb055

implemented kb_isdown(KB_ANY) correctly
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Sep 2013 04:07:09 +0300
parents c2b210a70ce9
children
line source
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <assert.h>
4 #include "keyb.h"
6 int main(void)
7 {
8 int key;
10 /* The argument to kb_init specifies how many keypresses to buffer up.
11 * If you don't need any keypress buffering, pass 0 to disable it.
12 */
13 kb_init(16);
15 printf("Press any key to continue ...\n");
17 /* example of active polling... The same can be done better by using
18 * kb_wait()
19 */
20 while(!kb_isdown(KB_ANY));
21 kb_getkey(); /* discard the key we just detected */
23 printf("Key tester, quit by pressing esc\n");
24 for(;;) {
25 kb_wait(); /* wait for any keypress */
26 key = kb_getkey(); /* get the pressed key */
27 assert(key != -1); /* this should never happen since kb_wait returned */
29 if(key == 27) break; /* quit on esc */
31 /* if it's a printable character print it along with the key value */
32 if(isprint(key)) {
33 printf("key: %d '%c'\n", key, (char)key);
34 } else {
35 printf("key: %d\n", key);
36 }
37 }
39 kb_shutdown();
40 return 0;
41 }