Skip to content

Instantly share code, notes, and snippets.

@mgronhol
Created May 11, 2012 08:18
Show Gist options
  • Save mgronhol/2658316 to your computer and use it in GitHub Desktop.
Save mgronhol/2658316 to your computer and use it in GitHub Desktop.
Näppiksen käsittely C:llä.
#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