bioskey
raw OCR
Keyboard interface, using BIOS services directly.
Defined in header <bios.h>
Syntax
#include <bios.h>
int bioskey(int cmd);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ |
Remarks
bioskey performs various keyboard operations using BIOS interrupt 0x16. The parameter cmd determines the exact operation.
Return value
The value returned by bioskey depends on the task it performs, determined by the value of cmd:
| 0 | If the lower 8 bits are nonzero, bioskey 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. |
| 1 | This tests whether a keystroke is available to be read. A return value of zero means no key is available. The return value is 0xFFFFF (-1) if Ctrt-Brk has been pressed. Otherwise, the value of the next keystroke is returned. The keystroke itself is kept to be returned by the next call to bioskey that has a cmd value of zero. |
| 2 | Requests the current shift key status. The value is obtained by ORing the following values together: | |
| 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 | Ctrl pressed |
| Bitl | 0x02 | <r- Shift pressed |
| BitO | 0x01 | -^ Shift pressed |
Example
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
ttdefine RIGHT 0x01,
#define LEFT 0x02
#define CTRL 0x04
ttdefine ALT 0x08
int main(void)
{
int key, modifiers;
/* function 1 returns 0 until a key is pressed */
while (bioskey(l) == 0);
/* function 0 returns the key that is waiting */
key = bioskey (0);
/* use function 2 to determine if shift keys are used */
modifiers = bioskey (2);
if (modifiers) {
printf(" [");
if (modifiers & RIGHT) printf ("RIGHT");
if (modifiers & LEFT) printf ("LEFT");
if (modifiers & CTRL) printf ("CTRL");
if (modifiers & ALT) printf ("ALT");
printf("]"),•
}
/* print out the character read */
if (isalnum(key & 0xFF))
printf("'%c'\n" , key);
else
printf("%t02x\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/bioskey/
· short form /3.1/bioskey/