Created
July 3, 2016 14:48
-
-
Save pkramme/5b482deaea7f1ca0e1b29050b1a40f3a to your computer and use it in GitHub Desktop.
getch.h
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
#ifndef _GETCH_H_ | |
#define _GETCH_H_ | |
#include <termios.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
/* reads from keypress, doesn't echo */ | |
int getch(void) | |
{ | |
struct termios oldattr, newattr; | |
int ch; | |
tcgetattr( STDIN_FILENO, &oldattr ); | |
newattr = oldattr; | |
newattr.c_lflag &= ~( ICANON | ECHO ); | |
tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); | |
ch = getchar(); | |
tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); | |
return ch; | |
} | |
/* reads from keypress, echoes */ | |
int getche(void) | |
{ | |
struct termios oldattr, newattr; | |
int ch; | |
tcgetattr( STDIN_FILENO, &oldattr ); | |
newattr = oldattr; | |
newattr.c_lflag &= ~( ICANON ); | |
tcsetattr( STDIN_FILENO, TCSANOW, &newattr ); | |
ch = getchar(); | |
tcsetattr( STDIN_FILENO, TCSANOW, &oldattr ); | |
return ch; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment