- 论坛徽章:
- 0
|
本帖最后由 木卫十二 于 2012-06-22 10:44 编辑
Thanks。
问题解决了,贴上新的代码(Linux下gcc调试通过):- #include <stdio.h>
- #include <termios.h>
- #include <unistd.h>
- #define ESC_CHAR '\\'
- int mygetch() {
- struct termios oldt,
- newt;
- int ch;
- tcgetattr( STDIN_FILENO, &oldt );
- newt = oldt;
- newt.c_lflag &= ~( ICANON | ECHO );
- tcsetattr( STDIN_FILENO, TCSANOW, &newt );
- ch = getchar();
- tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
-
- return ch;
- }
- int main(void)
- {
- int c;
-
- while((c = mygetch()) != EOF && c != 'q')
- {
-
- switch(c)
- {
- /* different keyboard, may have different ascii for backspace */
- case 127:
- putchar(ESC_CHAR);
- putchar('b');
- putchar('\n');
- break;
-
- /* different keyboard, may have different ascii for backspace */
- case 8:
- putchar(ESC_CHAR);
- putchar('b');
- putchar('\n');
- break;
-
- case 9:
- putchar(ESC_CHAR);
- putchar('t');
- putchar('\n');
- break;
-
- case ESC_CHAR:
- putchar(ESC_CHAR);
- putchar(ESC_CHAR);
- putchar('\n');
- break;
-
- default:
- printf("string=%c,ascii=%d.",c,c);
- putchar('\n');
- break;
- }
- }
-
- return 0;
- }
- $ ./a.out
- string=a,ascii=97.
- string=i,ascii=105.
- \\
- \b
- \t
复制代码 http://sleepycat.org/c/cpl/chapter1#p2 |
|