1 #include <stdio.h>
2 #include <termios.h>
3 
4 /* This program initialises the console in the same way as done by Msged, and
5    then reads keystrokes and reports the codes byte by byte. */
6 
7 static struct termios oldtios;
8 
main(void)9 int main(void)
10 {
11    struct termios tios;
12    int i, nq=0;
13 
14    tcgetattr(0, &tios);
15    oldtios = tios;
16    tios.c_lflag &= ~ICANON;
17    tios.c_lflag &= ~ECHO;
18    tios.c_lflag &= ~ISIG;
19    tios.c_cc[VMIN] = 0;
20    tios.c_cc[VTIME] = 0;
21    tcsetattr(0, TCSANOW, &tios);
22    setbuf(stdin, NULL);
23 
24    printf ("%c[1J%c[1;1H\
25 This program reads the keyboard in the same way as Msged does internally. It\n\
26 will show you the codes that correspond to your keystrokes exactly as the\n\
27 terminal driver reports them to Msged.\n\
28 \n\
29 These key codes can NOT be used as arguments for ReadKey or EditKey. The\n\
30 arguments for ReadKey and EditKey are PC'ish BIOS keyboard codes. Msged has\n\
31 internal tables to translate from the UNIX terminal driver keycode\n\
32 sequences to a PC'ish BIOS keyboard code.\n\
33 \n\
34 This tool is used to debug Msged's keycode translation tables. If you\n\
35 experience a problem of the sort that you press a certain key, but Msged does\n\
36 not react to it like expected, then you can use this tool to find out the raw\n\
37 keycode sequence and then contact the author of Msged to request support for\n\
38 this particular keycode to be added.\n\
39 \n\
40 Please note that a single keystroke may result in more than one keycode.\n\
41 \n\
42 ===> Press the \"q\" key three times in sequence to end this program. <====\n\
43 ",27,27);
44 
45    do
46    {
47        i = getchar();
48        if ( i != EOF )
49        {
50            printf ("%3dd %2xh ",i,i);
51            if (i>=32 && i <=127)
52                printf ("\'%c\'", (char) i);
53            printf ("\n");
54            if (i == 'q' || i == 'Q')
55                nq++;
56            else
57                nq=0;
58        }
59        else
60        {
61            clearerr(stdin);
62        }
63    } while (nq<3);
64 
65    tcsetattr(0, 0, &oldtios);
66    fflush(stdout);
67    return 0;
68 }
69 
70