T13.c 558 B

123456789101112131415161718192021222324
  1. #include <sys/types.h>
  2. #include <stdio.h>
  3. #include <termios.h>
  4. #include <unistd.h>
  5. static struct termios orig;
  6. static struct termios raw;
  7. static char buf[8];
  8. int main(void) {
  9. printf("Each keypress is echoed as 'c'. Press 'q' to quit.\n");
  10. tcgetattr(STDIN_FILENO, &orig);
  11. cfmakeraw(&raw);
  12. tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
  13. do {
  14. read(STDIN_FILENO, buf, sizeof(buf));
  15. printf("c");
  16. fflush(stdout);
  17. } while (buf[0] != 'q');
  18. tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig);
  19. printf("\n");
  20. return 0;
  21. }