非阻塞getch(),ncurses [英] Non-blocking getch(), ncurses
问题描述
我在使用ncurses'getch()阻止时遇到了一些问题。默认操作似乎是非阻塞的(或者我错过了一些初始化)?我希望它像Windows中的getch()一样工作。我尝试了各种版本的
I'm having some problems getting ncurses' getch() to block. Default operation seems to be non-blocking (or have I missed some initialization)? I would like it to work like getch() in Windows. I have tried various versions of
timeout(3000000);
nocbreak();
cbreak();
noraw();
etc...
(并非全部在同一时间)。如果可能的话,我宁愿不(明确)使用任何 WINDOW
。 A while while循环getch(),检查特定的返回值也可以。
(not all at the same time). I would prefer to not (explicitly) use any WINDOW
, if possible. A while
loop around getch(), checking for a specific return value is OK too.
推荐答案
curses库是一个包处理。如果没有正确初始化图书馆,你不能只拿出一套程序并希望获得最好的结果。这是一个正确阻止 getch()
的代码:
The curses library is a package deal. You can't just pull out one routine and hope for the best without properly initializing the library. Here's a code that correctly blocks on getch()
:
#include <curses.h>
int main(void) {
initscr();
timeout(-1);
int c = getch();
endwin();
printf ("%d %c\n", c, c);
return 0;
}
这篇关于非阻塞getch(),ncurses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!