问题
hey i have tested getch and getchar buts its wating for input , i think there must be an funktion who read the keyboard buffer. Part of my code
while (1) {
if (key!='r')
{
if (key!='q')
{
mvprintw(LINES-2, 1, "Display will refresh in %2d seconds ", t);
refresh();
sleep(1);
t--;
break;
}
else
{
exit (0);
}
}
else
{
return;
}
}
回答1:
If you don't want getch()
to wait, you have to set it up to be non-blocking, with nodelay()
.
After executing:
if (nodelay (pWin, 1) == ERR) {
// some error occurred.
}
then getch()
will return ERR
if no input is available.
The manpage for the input options is here and the behaviour of getch
is mentioned both there and in its own manpage as well, link here.
The nodelay option causes getch to be a non-blocking call. If no input is ready, getch returns ERR. If disabled (bf is FALSE), getch waits until a key is pressed.
In no-delay mode, if no input is waiting, the value ERR is returned.
来源:https://stackoverflow.com/questions/9208296/ncurses-keyboard-input