Adding upstream version 3.35.
[syslinux-debian/hramrach.git] / com32 / samples / keytest.c
blob9fd5755ae13c623ddeaa521923aa90d7ce1af177
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2004 H. Peter Anvin - All Rights Reserved
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.
11 * ----------------------------------------------------------------------- */
14 * keytest.c
16 * Test the key parsing library
19 #include <string.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <time.h>
23 #include <sys/times.h>
25 #include <consoles.h> /* Provided by libutil */
26 #include <getkey.h>
28 static void cooked_keys(void)
30 int key;
32 printf("[cooked]");
34 for(;;) {
35 key = get_key(stdin, 0);
37 if ( key == 0x03 ) {
38 printf("[done]\n");
39 exit(0);
40 } else if ( key == '?' )
41 return;
43 if ( key >= 0x20 && key < 0x100 ) {
44 putchar(key);
45 } else {
46 printf("[%04x]", key);
51 static void raw_keys(void)
53 int key;
55 printf("[raw]");
57 for(;;) {
58 key = getc(stdin);
60 if ( key == 0x03 ) {
61 printf("[done]\n");
62 exit(0);
63 } else if ( key == '!' )
64 return;
66 printf("<%02x>", key);
70 int main(void)
72 console_ansi_raw();
74 printf("CLK_TCK = %d\n", (int)CLK_TCK);
75 printf("Press keys, end with Ctrl-C...\n");
77 for (;;) {
78 cooked_keys();
79 raw_keys();