Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unistd.h>
- #include <termios.h>
- #include <sys/time.h>
- using namespace std;
- int unix_text_kbhit(void)
- {
- struct timeval tv = { 0, 0 };
- fd_set readfds;
- FD_ZERO(&readfds);
- FD_SET(STDIN_FILENO, &readfds);
- return select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv) == 1;
- }
- void mode_raw(int activer) //Terminal en modo RAW
- {
- static struct termios cooked;
- static int raw_actif = 0;
- if (raw_actif == activer)
- return;
- if (activer)
- {
- struct termios raw;
- tcgetattr(STDIN_FILENO, &cooked);
- raw = cooked;
- cfmakeraw(&raw);
- tcsetattr(STDIN_FILENO, TCSANOW, &raw);
- }
- else
- tcsetattr(STDIN_FILENO, TCSANOW, &cooked);
- raw_actif = activer;
- }
- int main (){
- while (true){
- mode_raw(1);
- if (unix_text_kbhit()!=0){mode_raw(0);cout<<(char) getchar()<<endl;}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement