I'm receiving input in a timed loop, and getch() blocks (waits for key) the program even though the loop has ended. When utilizing timeout(), or other functions, it doesn't block, but terminates the entire program.
initscr();
raw();
noecho();
while(time(NULL)-initTime < maxtime)
{
timeout(3); // 3 as an example
getch();
}
// do stuff
refresh();
// hit a key to exit
getch();
endwin();
That seems not useful, so I must be missing something. How to non-block (e.g within 3 seconds), and continue executing my code?
As also stated in the comments, the problem is with setting
timeoutonly once, and thus apply it to the whole program.The solution: