c 用于键盘捕获。以下代码查找何时按下箭头键/ esc。同时,我想阅读用户输入的整个单词,这些单词也应该显示在标准输出上。
char pp = 0;
char p = 0;
while( (i = read(0, &c, 1)) == 1) {
if (pp == 033 && p == 0133 && (c &= 255) == 0102) /* DOWN */ break;
if (c == 0177) /* ASCII DELETE */ break;
printf( "%o, %o, %o\t%s\n\r", pp, p, c, &c);
pp = p;
p = c;
}
...
...
getchar(); //I want to capture here what was entered before
// **return key** was pressed.
但是,如果我删除 '\n',此代码将不起作用。我希望标准输出应该表现得像一个普通的外壳。