6 A simple program to handle keys (in particular, function keys,
7 Ctrl keys, Alt keys and arrow keys).
8 This code is released to the public domain.
9 "Share and enjoy...." ;)
22 printf("Hey, you entered foo! \n");
27 printf("Hey, you entered bar! \n");
32 printf("Hey, you pressed ALT a! \n");
37 printf("Hey, you pressed ALT b! \n");
42 printf("Hey, you pressed CTRL a! \n");
47 printf("Hey, you pressed CTRL g! \n");
52 printf("Hey, you pressed the up arrow! \n");
57 printf("Hey, you pressed the down arrow! \n");
62 printf("Hey, you pressed the left arrow! \n");
65 void right_arrow(void)
67 printf("Hey, you pressed the right arrow! \n");
72 printf("Hey, you pressed F2! \n");
77 printf("Hey, you pressed F3! \n");
82 printf("Hey, you pressed F4! \n");
95 puts("Enter some text :");
98 if ( !strcmp(word, "foo") ) {
102 else if (!strcmp(word, "bar") ) {
106 else if (!strcmp(word, "\x1b\x61") ) {
110 else if (!strcmp(word, "\x1b\x62") ) {
114 else if (!strcmp(word, "\x07") ) {
118 else if (!strcmp(word, "\x01") ) {
122 else if (!strcmp(word, "\x1b\x5b\x41") ) {
126 else if (!strcmp(word, "\x1b\x5b\x42") ) {
130 else if (!strcmp(word, "\x1b\x5b\x43") ) {
134 else if (!strcmp(word, "\x1b\x5b\x44") ) {
138 else if (!strcmp(word, "\x1b\x4f\x51") ) {
142 else if (!strcmp(word, "\x1b\x4f\x52") ) {
146 else if (!strcmp(word, "\x1b\x4f\x53") ) {
151 printf("Nope - I do not recognise that phrase.... \n");
154 printf("Try again? (y/n) : ");
155 scanf(" %c%*c", &ch);
158 while( toupper(ch) != 'N' );