#include #include #include #include /* Use this variable to remember original terminal attributes. */ struct termios saved_attributes; void reset_input_mode() { tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes); } void set_input_mode() { struct termios tattr; char *name; /* Make sure stdin is a terminal. */ if (!isatty (STDIN_FILENO)) { fprintf (stderr, "Not a terminal.\n"); exit (EXIT_FAILURE); } /* Save the terminal attributes so we can restore them later. */ tcgetattr (STDIN_FILENO, &saved_attributes); atexit (reset_input_mode); /* Set the funny terminal modes. */ tcgetattr (STDIN_FILENO, &tattr); tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ tattr.c_cc[VMIN] = 1; tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr); } void delay(unsigned int ms) { usleep(ms * 1000); } char isKeyPressed() { char key_handler = 0; read(STDIN_FILENO, &key_handler, 1); if (key_handler > 0) { return 1; } return 0; } //int main() //{ // set_input_mode(); // while (isKeyPressed() == 0) {} // printf("ok"); // reset_input_mode(); //}