我目前正在通过 getch() while 循环收听键盘输入,一切正常。但是,如果我按住左键并向上按,则左移会停止,直到我再次按下它。我能想到解决这个问题的唯一方法是知道一个键是否被持有/何时释放。我正在使用据说具有这种能力的 ncurses,但通过我的所有搜索,我没有发现任何有用的东西。
俄罗斯方块代码片段有问题:
int ch = getch();
while(ch != 'x') {
// Handle arrow keys first
if (ch == '\033') {
getch(); // Get rid of slash
switch (getch()) {
case 'A': rotate(); redraw(); break; // Up
case 'B': move(DOWN); redraw(); break; // Down
case 'C': move(RIGHT); redraw(); break; // Right
case 'D': move(LEFT); redraw(); break; // Left
}
} else {
switch(ch) {
// Stuff not relevant to this question
}
}
ch = getch();
}