Ncurses Keyboard input

北城余情 提交于 2019-12-13 03:54:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!