Advertisement
magik6000

Untitled

Jan 15th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <termios.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7. #include <assert.h>
  8.  
  9. int mgetch(void) {
  10. int c=0;
  11.  
  12. struct termios org_opts, new_opts;
  13. int res=0;
  14. //----- store old settings -----------
  15. res=tcgetattr(STDIN_FILENO, &org_opts);
  16. assert(res==0);
  17. //---- set new terminal parms --------
  18. memcpy(&new_opts, &org_opts, sizeof(new_opts));
  19. new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
  20. tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
  21. c=getchar();
  22. //------ restore old settings ---------
  23. res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
  24. assert(res==0);
  25. return(c);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement