getch.c
来自「一个实现基本功能的shell命令解释器」· C语言 代码 · 共 38 行
C
38 行
#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <termios.h>#include <fcntl.h>int getch(void){ struct termios tm, tm_old; int fd = STDIN_FILENO; char c; if(tcgetattr(fd, &tm) < 0) printf("error!\n"); if(tcgetattr(fd, &tm_old) < 0) printf("error!\n"); cfmakeraw(&tm); if(tcsetattr(fd, TCSANOW, &tm) < 0) printf("error!\n"); c = fgetc(stdin); if(tcsetattr(fd, TCSANOW, &tm_old) < 0) printf("error!\n"); if(c == 0x38 || c == 0x32) { if(c == 0x38) { return -2; } else { return -1; } } else { return c; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?