kbhit用C语言
在这里,我们将看到C中的kbhit功能。kbhit基本上是KeyboardHit。此函数位于conio.h头文件中。因此,要使用此文件,我们必须将此头文件包含在我们的代码中。
其功能kbhit()是,当按下某个键时,它返回非零值,否则返回零。
示例
#include <stdio.h>
#include <conio.h>
main() {
char ch;
printf("Enter keys (ESC to exit)\n");
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\n", ch);
}
}
}输出结果
Enter keys (ESC to exit) You have entered : i You have entered : t You have entered : D You have entered : w You have entered : 5 You have entered : / You have entered : * You have entered : + You have entered : You have entered : o You have entered : You have entered : &
注意:这kbhit()不是标准库。因此,我们应该在代码中避免这种情况。
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬