简体   繁体   English

如何让“_getch()”不暂停 c 程序

[英]How to get “_getch()” to not pause c program

How can I get input from the user without pausing the program?如何在不暂停程序的情况下从用户那里获得输入? I have this program right here:我这里有这个程序:


#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
    while (1)
    {
        printf("loop\n");
        _getch();
        Sleep(80);
        
    }
}

How can I get it to do the while loop without pausing while still getting the input from the user?我怎样才能让它在不暂停的情况下执行while循环,同时仍然从用户那里获得输入?

I think I would add a timer in a loop in a second thread and if the user didnt apply input in a certain time, restart the getc() request.. on the first look, using 1 of my braincells it seems you are best off using another core due to the nature of the getc() and similar functions.我想我会在第二个线程的循环中添加一个计时器,如果用户在某个时间没有应用输入,请重新启动 getc() 请求。乍一看,使用我的一个脑细胞似乎你最好了由于 getc() 和类似功能的性质,使用另一个核心。 While you should also check the code of this function to see if there are faster ways同时您还应该检查此 function 的代码,看看是否有更快的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM