_bios_keybrd
Keyboard interface, using BIOS services directly.
Defined in header <bios.h>
Syntax
#include <bios.h>
unsigned _bios_keybrd(unsigned and);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
_bios_keybrd performs various keyboard operations using BIOS interrupt 0x16. The parameter cmd determines the exact operation.
Return value
The value returned by _blos_keybrd depends on the task it performs, determined by the value of cmd (defined in bios.h):
_KEYBRD_READ If the lower 8 bits are nonzero, _bios_keybrd returns the ASCII charac-ter for the next keystroke waiting in the queue or the next key pressed at the keyboard. If the lower 8 bits are zero, the upper 8 bits are the extended keyboard codes defined in the IBM PC Technical Reference Manual.
_NKEYBRD_READ
| Use this value instead of _KEYBRD_READY | to read the keyboard |
codes for enhanced keyboards, which have additional cursor and function keys.
_KEYBRD_READY This tests whether a keystroke is available to be read. A return value of zero means no key is available. The return value is 0xFFFF (-1) if Ctrl-Brk has been pressed. Otherwise, the value of the next keystroke is
| returned, as described in _KEYBRD_READ | (above). The keystroke |
itself is kept to be returned by the next call to _bios_keybrd that has a
| cmd value of _KEYBRD_READ | or _NKEYBRD_READ. |
_NKEYBRD_READY Use this value to check the status of enhanced keyboards, which have additional cursor and function keys.
_KEYBRD_SHIFrSTATUS Requests the current shift key status. The value will contain an OR of zero or more of the following values:
| Bit 7 | 0x80 | Insert on |
| Bit 6 | 0x40 | Caps on |
| Bits | 0x20 | Num Lock on |
| Bit 4 | 0x10 | Scroll Lock on |
| Bits | 0x08 | Alt pressed |
| Bit 2 | 0x04 | expressed |
| Bitl | 0x02 | Left SM pressed |
| BitO | 0x01 | Right Shnt pressed |
_NKEYBRD_SHIFTSTATUS
| Use this value instead of _KEYBRD_SHIFTSTATUS | to request the full |
16-bit shift key status for enhanced keyboards. The return value will contain an OR of zero or more of the bits defined above in
| _KEYBRD_SHIFrSTATUS, Bit 15 0x8000 Sys Req pressed | and additionally, any of the following bits: | |
| Bit 14 | 0x4000 | Caps Lock pressed |
| Bit 13 | 0x2000 | Num Lock pressed |
| Bit 12 | 0x1000 | Scro//Loc/c pressed |
| Bit 11 | 0x0800 | Right Alt pressed |
| Bit 10 | 0x0400 | Right Cm pressed |
| Bit 9 | 0x0200 | Left Alt pressed |
| Bit 8 | 0x0100 | Left CM pressed |
Example
#include <stdio.h>
#include <bios.h>
iinclude <ctype.h>
ttdefine RIGHT 0x01
tdefine LEFT 0x02
tdefine CTRL 0x04
tdefine ALT 0x08
int main (void)
1
int key, modifiers;
/* Wait until a key is pressed */
while (_bios_keybrd(_KEYBRD_READY) == 0);
/* Fetch the key that is waiting */
key = _bios_keybrd(_KEYBRD_READ);
/* Determine if shift keys are used */
modifiers = _bios_keybrd(_KEYBRD_SHIFTSTATUS)
if (modifiers)!
printf("["),•
if (modifiers & RIGHT) printf("RIGHT");
if (modifiers & LEFT) printf ("LEFT");
if (modifiers & CTRL) printf ("CTRL");
if (modifiers & ALT) printf("ALT"
printfC']");
/* print out the character read */
if (isalnum(key & 0xFF))
printf {"'%c'\n", key);
else
printf {"%#02x\n", key);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/bios.h/_bios_keybrd/
· short form /3.1/_bios_keybrd/