头文件:bios.h
int bioskey(int cmd)
cmd=0 返回一个键盘值,如无键盘按下,一直等待。
cmd=1 查询键盘是否按下 0-无键按下,非0-有键按下
cmd=2 返回控制键状态,返回值保存在低8位中
B0 右边的shift键按下 B5 已打开Scroll Lock
B1 左边的shift键按下 B6 已打开Num Lock
B3 Ctrl键按下 B7 已打开Caps Lock
B4 Alt键按下 B8 已打开Insert
实例:
以下给出tc3.0中的关于bioskey函数的例子,读一读会有好处的:
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#define RIGHT 0x01
#define LEFT 0x02
#define CTRL 0x04
#define ALT 0x08
int main(void)
{
int key, modifiers;
/* function 1 returns 0 until a key is pressed */
while (bioskey(1) == 0);
/* function 0 returns the key that is waiting */
key = bioskey(0);
/* use function 2 to determine if shift keys were 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("%#02x\n", key);
return 0;
}
本文地址:http://com.8s8s.com/it/it23465.htm