Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef LINUX_KBHIT_H_
- #define LINUX_KBHIT_H_
- #include <stdio.h>
- #include <termios.h>
- #include <unistd.h>
- //Source: http://muz.so/tzd
- int getch(void)
- {
- struct termios oldt,
- newt;
- int ch;
- tcgetattr( STDIN_FILENO, &oldt );
- newt = oldt;
- newt.c_lflag &= ~( ICANON | ECHO );
- tcsetattr( STDIN_FILENO, TCSANOW, &newt );
- ch = getchar();
- tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
- return ch;
- }
- //Source : http://muz.so/ugP
- int linux_kbhit(void)
- {
- struct termios oldt, newt;
- int ch;
- tcgetattr( STDIN_FILENO, &oldt );
- newt = oldt;
- newt.c_lflag &= ~( ICANON | ECHO );
- tcsetattr( STDIN_FILENO, TCSANOW, &newt );
- ch = getchar();
- tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
- return ch;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement