Advertisement
Gustavo541

Mapteclado

Mar 30th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<unistd.h>
  4. #include<termios.h>
  5.  
  6.  
  7. //mapeamento do teclado
  8.  
  9. #define especial 27
  10. #define especial2 91
  11. #define cima 65
  12. #define baixo 66
  13. #define enter 10
  14. #define espaco 32
  15. #define backspace 127
  16.  
  17.  
  18. void init_attr(struct termios *old_attr,struct termios *new_attr){
  19.     tcgetattr(0,&*old_attr);
  20.  
  21.     *new_attr=*old_attr;
  22.     new_attr->c_lflag &=~ICANON;
  23.     new_attr->c_cc[VMIN]=1;
  24.     new_attr->c_cc[VTIME]=0;
  25. }
  26.  
  27. int getch(){
  28.     struct termios old_attr, new_attr;
  29.     int c;
  30.  
  31.     init_attr(&old_attr,&new_attr);
  32.  
  33.     new_attr.c_lflag &=~ECHO;
  34.  
  35.     tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
  36.  
  37.     c=getchar();
  38.  
  39.     tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
  40.  
  41.     return c;
  42. }
  43.  
  44.  
  45. int main(){
  46.    
  47.     for(;;){
  48.        
  49.         int c = getch();
  50.         char a;
  51.    
  52.         if(c == especial){
  53.             c = getch();
  54.            
  55.             if(c == especial2){
  56.                 c = getch();
  57.                
  58.                 if(c == cima){
  59.                     printf("CIMA\n");
  60.                 }else if(c == baixo){
  61.                     printf("BAIXO\n");
  62.                 }
  63.             }
  64.         }else if(c == enter){
  65.                     printf("ENTER\n");
  66.         }else if(c == espaco){
  67.             printf("ESPACO\n");
  68.         }else if(c == backspace){
  69.             printf("BACKSPACE\n");
  70.         }else{
  71.             a = (char) c;
  72.             printf("%c\n",a);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement