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