home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / utility / keybrd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-27  |  1.1 KB  |  42 lines

  1. /* KEYBRD.C illustrates:
  2.  *      _bios_keybrd
  3.  */
  4.  
  5. #include <bios.h>
  6. #include <stdio.h>
  7. #include <ctype.h>
  8.  
  9. main()
  10. {
  11.     unsigned key, shift;
  12.     unsigned char scan, ascii = 0;
  13.  
  14.     /* Read and display keys until ESC is pressed. */
  15.     while( ascii != 27 )
  16.     {
  17.         /* Drain any keys in the keyboard type-ahead buffer, then get
  18.          * the current key. If you want the last key typed rather than
  19.          * the key currently being typed, omit the initial loop.
  20.          */
  21.         while( _bios_keybrd( _KEYBRD_READY ) )
  22.             _bios_keybrd( _KEYBRD_READ );
  23.         key = _bios_keybrd( _KEYBRD_READ );
  24.  
  25.         /* Get shift state. */
  26.         shift = _bios_keybrd( _KEYBRD_SHIFTSTATUS );
  27.  
  28.         /* Split key into scan and ascii parts. */
  29.         scan = key >> 8;
  30.         ascii = key & 0x00ff;
  31.  
  32.         /* Categorize key. */
  33.         if( ascii )
  34.             printf( "ASCII: yes\tChar: %c \t",
  35.                     isgraph( ascii ) ? ascii : ' ' );
  36.         else
  37.             printf( "ASCII: no\tChar: NA\t" );
  38.         printf( "Code: %.2X\tScan: %.2X\t Shift: %.2X\n",
  39.                 ascii, scan, shift );
  40.     }
  41. }
  42.