syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / com32 / samples / keytest.c
1 #ident "$Id: keytest.c,v 1.4 2004/12/21 23:31:45 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2004 H. Peter Anvin - All Rights Reserved
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * keytest.c
16  *
17  * Test the key parsing library
18  */
19
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <sys/times.h>
25
26 #include <consoles.h>           /* Provided by libutil */
27 #include <getkey.h>
28
29 static void cooked_keys(void)
30 {
31   int key;
32
33   printf("[cooked]");
34
35   for(;;) {
36     key = get_key(stdin, 0);
37
38     if ( key == 0x03 ) {
39       printf("[done]\n");
40       exit(0);
41     } else if ( key == '?' )
42       return;
43     
44     if ( key >= 0x20 && key < 0x100 ) {
45       putchar(key);
46     } else {
47       printf("[%04x]", key);
48     }
49   }
50 }
51
52 static void raw_keys(void)
53 {
54   int key;
55
56   printf("[raw]");
57
58   for(;;) {
59     key = getc(stdin);
60
61     if ( key == 0x03 ) {
62       printf("[done]\n");
63       exit(0);
64     } else if ( key == '!' )
65       return;
66     
67     printf("<%02x>", key);
68   }
69 }
70
71 int main(void)
72 {
73   console_ansi_raw();
74
75   printf("CLK_TCK = %d\n", (int)CLK_TCK);
76   printf("Press keys, end with Ctrl-C...\n");
77
78   for (;;) {
79     cooked_keys();
80     raw_keys();
81   }
82 }