0
我使用Linux和ncurses为我的应用程序,我使用getch作为非阻塞使用nodelay。问题在于,当用输入的getch循环时,它总是错过第一个字符。例如,输入“Helloworld”将打印为“elloworld”。 我目前似乎没有看到任何问题,虽然也许它是因为我一直在盯着远远长的代码,或者我错过了一些东西。Ncurses,非阻塞getch错过了第一个字符
while(TRUE)
{
gchar chr;
gchar *cmd = g_malloc(50);
if((getch()) == ERR)
{
// no user input
}
else
{
gint i = 0;
while((chr = getch()) != '\n')
{
cmd[i] = chr;
waddch(ncurse->window, chr);
wrefresh(ncurse->window);
i++;
}
waddstr(ncurse->log, cmd);
wrefresh(ncurse->log);
wmove(ncurse->window, ncurse->window->_maxy, 2);
wclrtoeol(ncurse->window);
wrefresh(ncurse->window);
}
g_free(cmd);
}
感谢您为我们带来了一双清新的眼睛,并推向正确的方向,现在它已经固定下来了。 – Bennu