DOS下的C/C++程序如何用“Alt”+“X”组合键实现退出功能?
DOS下的C/C++程序怎么用“Alt”+“X”组合键实现退出功能???
DOS下的C/C++程序怎么用“Alt”+“X”组合键实现退出功能???
其键码是什么,
ch=getch()
if(ch==0x00)
then...??
下一步怎么判断
------解决方案--------------------
int bioskey(int cmd)本函数用来执行各种键盘操作,由cmd确定操作。
cmd可为以下值:
0 返回敲键盘上的下一个键。若低8位为非0,即为ASCII字符;若低8位为0,
则返回扩充了的键盘代码。
1 测试键盘是否可用于读。返回0表示没有键可用;否则返回下一次敲键之值。
敲键本身一直保持由下次调用具的cmd值为0的bioskey所返回的值。
2 返回当前的键盘状态,由返回整数的每一个位表示,见下表:
┌──┬───────────┬───────────┐
│ 位 │为0时意义 │为1时意义 │
├──┼───────────┼───────────┤
│ 7 │插入状态 │改写状态 │
│ 6 │大写状态 │小写状态 │
│ 5 │数字状态,NumLock灯亮 │光标状态,NumLock灯熄 │
│ 4 │ScrollLock灯亮 │ScrollLock灯熄 │
│ 3 │Alt按下 │Alt未按下 │
│ 2 │Ctrl按下 │Ctrl未按下 │
│ 1 │左Shift按下 │左Shift未按下 │
│ 0 │右Shift按下 │右Shift未按下 │
└──┴───────────┴───────────┘
函数名: bioskey
功 能: 直接使用BIOS服务的键盘接口
用 法: int bioskey(int cmd);
程序例:
#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;
}
DOS下的C/C++程序怎么用“Alt”+“X”组合键实现退出功能???
其键码是什么,
ch=getch()
if(ch==0x00)
then...??
下一步怎么判断
------解决方案--------------------
int bioskey(int cmd)本函数用来执行各种键盘操作,由cmd确定操作。
cmd可为以下值:
0 返回敲键盘上的下一个键。若低8位为非0,即为ASCII字符;若低8位为0,
则返回扩充了的键盘代码。
1 测试键盘是否可用于读。返回0表示没有键可用;否则返回下一次敲键之值。
敲键本身一直保持由下次调用具的cmd值为0的bioskey所返回的值。
2 返回当前的键盘状态,由返回整数的每一个位表示,见下表:
┌──┬───────────┬───────────┐
│ 位 │为0时意义 │为1时意义 │
├──┼───────────┼───────────┤
│ 7 │插入状态 │改写状态 │
│ 6 │大写状态 │小写状态 │
│ 5 │数字状态,NumLock灯亮 │光标状态,NumLock灯熄 │
│ 4 │ScrollLock灯亮 │ScrollLock灯熄 │
│ 3 │Alt按下 │Alt未按下 │
│ 2 │Ctrl按下 │Ctrl未按下 │
│ 1 │左Shift按下 │左Shift未按下 │
│ 0 │右Shift按下 │右Shift未按下 │
└──┴───────────┴───────────┘
函数名: bioskey
功 能: 直接使用BIOS服务的键盘接口
用 法: int bioskey(int cmd);
程序例:
#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;
}