kbhit()函数解析

kbhit


函数名:kbhit()
功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0。
用 法:int kbhit(void);
C++语言包含头文件: include <conio.h>。
C语言不需包含额外头文件。
在VC++6.0下为_kbhit()
功能及返回值同上;

C++语言实现

1
2
3
4
5
6
7
8
9
10
11
12
#include<conio.h>
#include<iostream>
using  namespace  std;
int  main()
{
while (!kbhit()) //当没有键按下
{
cout<< "无键按下" <<endl;
}
cout<< "有键按下" <<endl; //有键按下时输出这
system ( "pause" );
}
kbhit()在执行时,检测是否有按键按下,有按下返回非0值,没有按下则返回0,是非阻塞函数;
不同于getch()的在执行时,检测按下什么键,如果不按键该函数不返回,也就不进行下一步操作,是阻塞函数。
类似地,在TC2.0中有一个处理键盘输入的函数 bioskey();

猜你喜欢

转载自www.cnblogs.com/booksBlog/p/10343550.html