home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap13 / scancode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  906 b   |  31 lines

  1. /*   scancode.c -- displays ASCII or scan code         */
  2. /*   This program illustrates using getch() to detect  */
  3. /*   special keys such as function keys.               */
  4.  
  5. #include <conio.h>
  6. #define ESC '\033'     /* ESC key */
  7. main()
  8. {
  9.      int ch;
  10.  
  11.      printf("Strike keys and see the codes!\n");
  12.      printf("Press the Esc key to quit.\n");
  13.  
  14.      while ((ch = getch()) != ESC)
  15.           {
  16.           if (ch != 0)
  17.                {
  18.                if (ch <= 32)    /* control characters */
  19.                     printf("^%c has ASCII code %d\n",
  20.                             ch + 64, ch);
  21.                else
  22.                     printf("%c has ASCII code %d\n", ch, ch);
  23.                }
  24.           else              /* ch IS 0 */
  25.                {
  26.                ch = getch();  /* get scan code */
  27.                printf("Scan code is %d\n", ch);
  28.                }
  29.           }
  30. }
  31.