MUstar

IoT C언어 0807 - 여름방학프로젝트(resource/nyamain.h)

Aug 9th, 2017
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef LINUX_KBHIT_H_
  2. #define LINUX_KBHIT_H_
  3.  
  4. #include <stdio.h>
  5. #include <termios.h>
  6. #include <unistd.h>
  7.  
  8. //Source: http://muz.so/tzd
  9. int getch(void)
  10. {
  11.     struct termios oldt,
  12.     newt;
  13.     int ch;
  14.     tcgetattr( STDIN_FILENO, &oldt );
  15.     newt = oldt;
  16.     newt.c_lflag &= ~( ICANON | ECHO );
  17.     tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  18.     ch = getchar();
  19.     tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  20.     return ch;
  21. }
  22.  
  23. //Source : http://muz.so/ugP
  24. int linux_kbhit(void)
  25. {
  26.     struct termios oldt, newt;
  27.     int ch;
  28.  
  29.     tcgetattr( STDIN_FILENO, &oldt );
  30.     newt = oldt;
  31.  
  32.     newt.c_lflag &= ~( ICANON | ECHO );
  33.     tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  34.  
  35.     ch = getchar();
  36.  
  37.     tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  38.  
  39.     return ch;
  40. }
  41. #endif
RAW Paste Data