Ncurses键盘输入 [英] Ncurses Keyboard input
问题描述
嘿,我已经测试过getch和getchar,但是它想输入一些东西,我认为读取键盘缓冲区的功能一定很不错. 我的代码的一部分
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;
}
}
推荐答案
如果您不希望getch()
等待,则必须使用nodelay()
将其设置为非阻塞.
If you don't want getch()
to wait, you have to set it up to be non-blocking, with nodelay()
.
执行后:
if (nodelay (pWin, 1) == ERR) {
// some error occurred.
}
然后,如果没有可用的输入,getch()
将返回ERR
.
then getch()
will return ERR
if no input is available.
输入选项的联机帮助页为此处,而getch
的行为为在此处以及在其自己的联机帮助页中都提到过,请在此处链接.
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.
nodelay选项使getch成为非阻塞调用.如果没有任何输入准备就绪,getch将返回ERR.如果被禁用(bf为FALSE),getch将等待直到按下某个键.
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.
在无延迟模式下,如果没有输入在等待,则返回值ERR.
In no-delay mode, if no input is waiting, the value ERR is returned.
这篇关于Ncurses键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!