
在这里,我们将看到 C 中的 kbhit 功能。kbhit 基本上是键盘敲击。该函数位于 conio.h 头文件中。因此,为了使用它,我们必须将此头文件包含到我们的代码中。
kbhit() 的功能是,当按下某个键时,它返回非零值,否则返回零。
#include <stdio.h>
#include <conio.h>
main() {
char ch;
printf("Enter keys (ESC to exit)</p><p>");
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</p><p>", 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() 不是标准库。所以我们应该在代码中避免这种情况。
以上就是在C语言中,kbhit指的是检测键盘是否有输入的函数的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号