Reading Extended Keyboard Characters with C

Last reviewed: July 17, 1997
Article ID: Q43007
6.00 6.00a 6.00ax 7.00 | 1.00 1.50
MS-DOS                 | WINDOWS
kbprg

The information in this article applies to:

  • Microsoft C for MS-DOS, versions 6.0, 6.0a, and 6.0ax
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SUMMARY

The _bios_keybrd() function uses INT function 16H to access the keyboard services. The C 5.1 _bios_keybrd function() is based on the original PC BIOS INT 16H, which does not support the extended keyboard. The BIOS for AT's and PS/2's has been updated to support the extended keyboard. The updated BIOS has three addition services: 10H reads a character from the extended keyboard, 11H gets the extended-keyboard status, 12H gets the extended-keyboard flags.

To allow the C 5.1 _bios_keybrd() to use these updated keyboard services, define the following manifest constants.

   #define _NKEYBRD_READ          0x10  /* read extended chars */
   #define _NKEYBRD_READY         0x11  /* check if key waiting */
   #define _NKEYBRD_SHIFT_STATUS  0x12  /* check shift key status */

To read keys from the extended keyboard, use these new constants in place of the manifest constants described on page 138 of the "Microsoft C for the MS-DOS Operating System: Run-Time Library Reference" for version 5.1.

These constants are already defined in C versions 6.0 and later.

MORE INFORMATION

The following program uses the enhanced services of INT function 16H to determine if the UP ARROW or DOWN ARROW keys on the extended keyboard were pressed. Uncomment the #define for C 5.1 and earlier.

Sample Code:

/* Compile options needed: none
*/

/* #define _NKEYBRD_READ 0x10 */
#include <bios.h>
#include <stdio.h>

void main()
{
   unsigned key;

   key = _bios_keybrd( _NKEYBRD_READ );

   if ( key == 0x48e0 )
      printf( "Up arrow was pressed.\n" );
   else if ( key == 0x50e0 )
      printf( "Down arrow was pressed.\n" );
   else
      printf( "Neither the up or the down arrow was pressed.\n" );
}


Additional reference words: kbinf 6.00 6.00a 6.00ax 7.00 1.00 1.50
KBCategory: kbprg
KBSubcategory: CLngIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.