Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<unistd.h>
- #include<termios.h>
- //mapeamento do teclado
- #define especial 27
- #define especial2 91
- #define cima 65
- #define baixo 66
- #define enter 10
- #define espaco 32
- #define backspace 127
- void init_attr(struct termios *old_attr,struct termios *new_attr){
- tcgetattr(0,&*old_attr);
- *new_attr=*old_attr;
- new_attr->c_lflag &=~ICANON;
- new_attr->c_cc[VMIN]=1;
- new_attr->c_cc[VTIME]=0;
- }
- int getch(){
- struct termios old_attr, new_attr;
- int c;
- init_attr(&old_attr,&new_attr);
- new_attr.c_lflag &=~ECHO;
- tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
- c=getchar();
- tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
- return c;
- }
- int main(){
- for(;;){
- int c = getch();
- char a;
- if(c == especial){
- c = getch();
- if(c == especial2){
- c = getch();
- if(c == cima){
- printf("CIMA\n");
- }else if(c == baixo){
- printf("BAIXO\n");
- }
- }
- }else if(c == enter){
- printf("ENTER\n");
- }else if(c == espaco){
- printf("ESPACO\n");
- }else if(c == backspace){
- printf("BACKSPACE\n");
- }else{
- a = (char) c;
- printf("%c\n",a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement