Created
May 11, 2012 08:18
-
-
Save mgronhol/2658316 to your computer and use it in GitHub Desktop.
Näppiksen käsittely C:llä.
This file contains hidden or 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 <stdlib.h> | |
#include <unistd.h> | |
#include <termios.h> | |
int main(){ | |
char buffer[2]; | |
struct termios tty_config; | |
tcgetattr(0, &tty_config ); | |
tty_config.c_lflag &= ~ICANON; | |
tty_config.c_lflag &= ~ECHO; | |
tty_config.c_cc[VMIN] = 1; | |
tty_config.c_cc[VTIME] = 0; | |
tcsetattr( 0, TCSANOW, &tty_config ); | |
read( 0, &buffer, 1 ); | |
printf( "Painoit nappulaa (%c)!\n", buffer[0] ); | |
tty_config.c_lflag |= ICANON; | |
tty_config.c_lflag |= ECHO; | |
tcsetattr( 0, TCSADRAIN, &tty_config ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment