kbhit() 的功能是,当按下某个键时,它返回非零值,否则返回零。
示例#include <stdio.h>#include <conio.h>main() { char ch; printf("enter keys (esc to exit)
"); while (1) { //define infinite loop for taking keys if (kbhit) { ch = getch(); // get typed character into ch if ((int)ch == 27) //when esc button is pressed, then it will comeout from loop break; printf("you have entered : %c
", ch); } }}
输出enter keys (esc to exit)you have entered : iyou have entered : tyou have entered : dyou have entered : wyou have entered : 5you have entered : /you have entered : *you have entered : +you have entered :you have entered : oyou have entered :you have entered : &
注意:这个 kbhit() 不是标准库。所以我们应该在代码中避免这种情况。
以上就是在c语言中,kbhit指的是检测键盘是否有输入的函数的详细内容。
