如您所知,在 Windows 中使用 getch() 时,应用程序会等待您按下某个键,
如何在不卡住程序的情况下读取 key ,例如:
void main(){
char c;
while(1){
printf("hello\n");
if (c=getch()) {
.
.
.
}
}
谢谢。
最佳答案
您可以使用kbhit()
来检查是否按下了某个键:
#include <stdio.h>
#include <conio.h> /* getch() and kbhit() */
int
main()
{
char c;
for(;;){
printf("hello\n");
if(kbhit()){
c = getch();
printf("%c\n", c);
}
}
return 0;
}
更多信息请点击:http://www.programmingsimplified.com/c/conio.h/kbhit
关于c 编程检查是否按下按键而不停止程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55606641/