Last active
August 29, 2015 14:09
-
-
Save embed/51967829b990b3c85c7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <termios.h> | |
int main() | |
{ | |
struct termios old_tio, new_tio; | |
unsigned char c; | |
/* get the terminal settings for stdin */ | |
tcgetattr(STDIN_FILENO,&old_tio); | |
/* we want to keep the old setting to restore them a the end */ | |
new_tio=old_tio; | |
/* disable canonical mode (buffered i/o) and local echo */ | |
new_tio.c_lflag &=(~ICANON & ~ECHO); | |
/* set the new settings immediately */ | |
tcsetattr(STDIN_FILENO,TCSANOW,&new_tio); | |
do { | |
c=getchar(); | |
printf("%d ",c); | |
} while(c!='q'); | |
/* restore the former settings */ | |
tcsetattr(STDIN_FILENO,TCSANOW,&old_tio); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment