【发布时间】:2016-01-01 03:19:20
【问题描述】:
好的,我在下面使用的代码效果很好,除了打印出键 RETURN 和 SPACE 的正确信息。 我尝试了很多方法,但这个似乎是最接近的。
更新:根据 Thomas Dickey 的推荐,
#include <ncurses.h>
int main()
{
initscr();
cbreak(); /* as per recommend Thomas Dickey */
noecho(); /* as per recommend Thomas Dickey */
int c, SPACE=32, RETURN=10; /* i know this is wrong but..? */
/* with changes return key is 10 , yet name for keys SPACE && RETURN
do not display, which is the gist of my question.
What am i missing? */
printw("Write something (ESC to escape): ");
move(2,0);
while((c=getch())!=27)
{
//move(2,0);
printw("Keycode: %d, and the character: %c\n", c, c);
refresh();
}
endwin();
return 0;
}
这是终端输出:更新后,
Write something (ESC to escape):
Keycode: 32, and the character: <--spacebar,- no label
Keycode: 10, and the character: <--enter/return key - no label
Keycode: 121, and the character: y
Keycode: 97, and the character: a
Keycode: 109, and the character: m
Keycode: 115, and the character: s
我觉得仍然不知所措.... xD.
我正在关注来自 youtube 用户 thecplusplusguy 的 this tutorial,尽管它实际上不是 C++。
要清楚,上面的输出是我想要的,除了空格键和返回键的“缺失”标签。
谢谢。
这一切都导致了一个基于终端的阅读器,用于项目古腾堡版本。我需要做一些新的事情。 Android 很烦人。
【问题讨论】: