wgetch 未检测到 KEY_UP 等
wgetch is not detecting KEY_UP etc
我已经为 my_win 启用了键盘,但是当我在 运行 程序后按 KEY_UP 时,没有任何反应。奇怪的是它与 stdscr 一起工作得很好。这似乎只是 my_win.
的问题
/* Selects different elements of the list */
while ((ch = wgetch(my_win)) != 'q')
{
sprintf(item, "%-12s", list[i]);
mvwprintw(my_win, i + 1, 2, "%s", item);
switch(ch)
{
case KEY_LEFT:
destroy_win(my_win);
my_win = create_newwin(height, width, starty,--startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 'd':
destroy_win(my_win);
my_win = create_newwin(height, width, starty,++startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 'w':
destroy_win(my_win);
my_win = create_newwin(height, width, --starty,startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 's':
destroy_win(my_win);
my_win = create_newwin(height, width, ++starty,startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case KEY_UP:
i--;
i = (i < 0) ? 4 : i;
break;
case KEY_DOWN:
i++;
i = (i < 0) ? 4 : i;
break;
}
keypad
函数仅适用于作为其参数给出的 window。当你使用 newwin
等时,那些 return a window 未设置键盘模式的
newwin
文档指出
Regardless of the function used for creating a new window (e.g.,
newwin
, subwin
, derwin
, newpad
), rather than a duplicate (with dupwin),
all of the window modes are initialized to the default values. These
functions set window modes after a window is created:
idcok, idlok, immedok, keypad, leaveok, nodelay, scrollok,
setscrreg, syncok, wbkgdset, wbkgrndset, and wtimeout
我已经为 my_win 启用了键盘,但是当我在 运行 程序后按 KEY_UP 时,没有任何反应。奇怪的是它与 stdscr 一起工作得很好。这似乎只是 my_win.
的问题/* Selects different elements of the list */
while ((ch = wgetch(my_win)) != 'q')
{
sprintf(item, "%-12s", list[i]);
mvwprintw(my_win, i + 1, 2, "%s", item);
switch(ch)
{
case KEY_LEFT:
destroy_win(my_win);
my_win = create_newwin(height, width, starty,--startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 'd':
destroy_win(my_win);
my_win = create_newwin(height, width, starty,++startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 'w':
destroy_win(my_win);
my_win = create_newwin(height, width, --starty,startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case 's':
destroy_win(my_win);
my_win = create_newwin(height, width, ++starty,startx);
wprintw(my_win, "This is some text");
wrefresh(my_win);
break;
case KEY_UP:
i--;
i = (i < 0) ? 4 : i;
break;
case KEY_DOWN:
i++;
i = (i < 0) ? 4 : i;
break;
}
keypad
函数仅适用于作为其参数给出的 window。当你使用 newwin
等时,那些 return a window 未设置键盘模式的
newwin
文档指出
Regardless of the function used for creating a new window (e.g.,
newwin
,subwin
,derwin
,newpad
), rather than a duplicate (with dupwin), all of the window modes are initialized to the default values. These functions set window modes after a window is created:idcok, idlok, immedok, keypad, leaveok, nodelay, scrollok, setscrreg, syncok, wbkgdset, wbkgrndset, and wtimeout