【发布时间】:2015-04-02 11:52:29
【问题描述】:
我使用 ncurse 创建了一个窗口,我试图能够在窗口内使用箭头键移动光标,并且只能在窗口内移动。据我了解,我必须使用wmove(),但显然我不知道如何使用它。
这里有一些代码 sn-ps 让你知道我做了什么:
int main(int argc, char **argv)
{
WINDOW *my_win;
int startx, starty, width, height;
int ch;
int x = 50;
int y = 5;
initscr();
cbreak();
keypad(stdscr, TRUE);
noecho();
height = 10;
width = 100;
starty = (LINES - height) / 2;
startx = (COLS - width) / 2;
printw("Press F1 to exit");
refresh();
my_win = create_newwin(25, 50, y, x);
wmove(my_win, y, x);
while((ch = getch()) != KEY_F(1))
{
if ((ch = getch()) == KEY_RIGHT)
wmove(my_win, y++, x++);
refresh();
}
endwin();
return 0;
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{
WINDOW *local_win;
local_win = newwin(height, width, starty, startx);
box(local_win, 0, 0);
wrefresh(local_win);
return (local_win);
}
【问题讨论】:
-
对ncurses不太熟悉,但是
create_newwin(25, 50, y, x)应该是create_newwin(starty, startx, height, width)吗?然后看起来您将光标放在带有wmove(my_win, y, x)的右下角,并且当按下KEY_RIGHT时,尝试将其向下和向右移动,而此时您已经走到了尽头朝着那个方向。 -
@Steve 我刚刚编辑了我的问题,让您看到我的 create_newwin。根据我的功能, create_newwin(25, 50, y, x) 似乎工作正常。