Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_bios_keybrd() access keyboard services</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _bios_keybrd()          Access keyboard services

 #include   <bios.h>

 unsigned int _bios_keybrd(service);
  unsigned service;      Keyboard service desired -- use one of the manifest
                         constants described below.

    _bios_keybrd() accesses the keyboard services using ROM-BIOS
    interrupt 16h. The three available services are selected using one of
    these manifest constants:

 _KEYBRD_READ   Returns the next character in the keyboard buffer. If no
                character is available, this service waits until one is
                available, halting normal processing. A two byte integer
                is returned. If the low-order byte is non-zero, it
                contains the ASCII value of the keyboard character. The
                high-order byte contains the keyboard scan code for the
                character. See Keyboard Codes under Tables for the ASCII
                and scan code values associated with each key.

 _KEYBRD_READY  Checks to see if a character is available in the buffer,
                and if so returns its ASCII and scan code value, as
                above. The character is left in the buffer until
                _KEYBRD_READ is next called. If there is no waiting
                character a zero is returned.

 _KEYBRD_SHIFTSTATUS     Returns the status of the shift, control, alt,
                and lock keys in the low-order byte. The meaning of the
                individual bits is as follows:

                    Low-order byte       Shift Status
                    7 6 5 4 3 2 1 0
                    1 . . . . . . .      Insert locked
                    . 1 . . . . . .      Caps Lock locked
                    . . 1 . . . . .      Num Lock locked
                    . . . 1 . . . .      Scroll Lock locked
                    . . . . 1 . . .      Alt key is pressed
                    . . . . . 1 . .      Ctrl key is pressed
                    . . . . . . 1 .      Left Shift key is pressed
                    . . . . . . . 1      Right Shift key is pressed

    Returns:        Two-byte integer with values described above.

    Notes:          The _KEYBRD_READY service is useful for allowing
                    another process to continue while waiting for
                    keyboard input, or interrupting a process when a key
                    is pressed. Used with _KEYBRD_READ it is also useful
                    for emptying the keyboard buffer before critical
                    keyboard input is accepted.

                    If you are programming for the PCJr note that eight
                    additional services are available by accessing ROM-
                    BIOS interrupt 16h using intdos(), intdosx(), or
                    assembly language. If you are programming for the AT
                    or PS/2, there are 5 additional services available by
                    the same means.

 Portability:   MS-DOS and true PC compatibles only.

------------------------------- Example ---------------------------------

 This program repeatedly puts a statement to the screen until any key or
 key-combination is pressed. Note that the shift, ctrl, alt, and lock
 keys, if used, must be pressed with another key before _KEYBRD_READY
 can detect it.

           #include             <bios.h>

           main()
           {
              unsigned key;

              while (1)
                 {
                 printf("\n\tPress any key or key-combination to stop");
                 if (_bios_keybrd(_KEYBRD_READY))
                    {
                    key = _bios_keybrd(_KEYBRD_READ);
                    printf("\nYou pressed the key/combination with");
                    printf(" scan code %d decimal, %2X hex", key >> 8, key >>
           8);
                    printf("\nThe ASCII value of the character is \'%c\'",
           key);
                    printf("\n\n\t\tThanks!");
                    break;
                    }
                 }
           }


See Also: int86() intdos()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson