📄 p9-8.c
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <termios.h>#include <signal.h>#include <unistd.h>#define TTY_OUTPUT 1static struct termios old_term;static struct termios new_term;void do_exit(int);void set_tty(){ /* 不处理回车和换行符,忽略BREAK条件 */ new_term.c_iflag &= ~(ICRNL | IGNCR | INLCR | IGNBRK | BRKINT); new_term.c_oflag &= ~OPOST; /* 无实现定义的输出处理 */ new_term.c_lflag |= ISIG | NOFLSH; /* 生成终端信号,但不清除输出队列 */ new_term.c_lflag &= ~(ICANON); /* 非加工方式 */ new_term.c_cc[VINTR] = 7; /* ^G 作为中断字符 */ new_term.c_cc[VQUIT] = 7; /* ^G 作为退出字符 */ new_term.c_cc[VMIN] = 1; new_term.c_cc[VTIME] = 0; tcsetattr(TTY_OUTPUT, TCSADRAIN, &new_term);}void tty_init(){ tcgetattr(TTY_OUTPUT, &old_term); signal(SIGTERM, do_exit); signal(SIGQUIT, do_exit); signal(SIGINT, do_exit); /* signal(SIGTSTP, do_exit); */ /* signal(SIGCONT, set_tty); */ new_term = old_term; set_tty();}void tty_end(){ tcsetattr(TTY_OUTPUT, TCSADRAIN, &old_term);}void do_exit(int signum){ tty_end(); exit(1);}int main(){ char c; printf("Display key sequence utility\n"); printf("Press space when done.\n\n"); tty_init(); for (;;) { read(0, &c, 1); if (c == ' ') break; printf("%o\n", c); fflush(stdout); } tty_end(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -