#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <termios.h> int main(void) { #if 0 int n = 10; while(1) { if((n--) == 0) { printf("over n=%d\n", n); break; } printf("n=%d\n", n); } #endif unsigned char buf[1024]; bzero(buf, 1024); read(0, buf, 1024); printf("buf:%s\n", buf); #if 1 //终端属性描述结构体 struct termios oldattr, newattr; //获取当前终端的属性 tcgetattr(0, &oldattr); //将newattr设置为原始属性 cfmakeraw(&newattr); //将终端设置为原始属性 tcsetattr(0, TCSANOW, &newattr); while(1) { bzero(buf, 1024); read(0, buf, 1024); printf("%u\t%u\t%u\t%u\n", buf[0], buf[1], buf[2],buf[3]); } //将终端恢复原来的属性 tcsetattr(0, TCSANOW, &oldattr); sleep(1); bzero(buf, 3); read(0, buf, 3); printf("%c\t%c\t%c\n", buf[0], buf[1], buf[2]); #endif #if 0 //终端属性描述结构体 struct termios oldattr, newattr; //获取当前终端的属性 tcgetattr(0, &oldattr); //将newattr设置为原始属性 cfmakeraw(&newattr); //将终端设置为原始属性 tcsetattr(0, TCSANOW, &newattr); bzero(buf, 1024); read(0, buf, 1024); printf("%c\t%c\t%c\t%c\n", buf[0], buf[1], buf[2], buf[3]); //将终端恢复原来的属性 tcsetattr(0, TCSANOW, &oldattr); sleep(1); bzero(buf, 1024); read(0, buf, 1024); printf("%c\t%c\t%c\t%c\n", buf[0], buf[1], buf[2], buf[3]); #endif return 0; } |
|