自己编制一个利用键盘控制程序运行的C语言小程序,并调试运行。

来源:百度知道 编辑:UC知道 时间:2024/05/24 02:17:53
C语言实训练习
二、相关知识
1、kbhit()函数
包含在头文件conio.h中,检测是否有按键动作。
2、bioskey()函数
包含在头文件bios.h中,返回所按键盘的键值。
#define ESC 0x011b
main()
{
int k;
while(k!=ESC){ /*循环,直到按ESC键退出*/
if(kbhit()){ /*检测是否有按键动作*/
k=bioskey(0); /*返回按键的扫描码,参数为0 清空键盘缓冲区,为1不清空键盘缓冲区*/
printf("%x\n",k);
}
}
}
这是他给的程序,要求编写一个相似的!!

已编译确认:
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.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