1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <termios.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
int main()
{
int c;
while(c != EOF) {
mode_raw(1);
c = getchar();
switch(c) {
case EOF:cexit();
break;
case 4:cexit();
break;
case 27:c=getchar();
if (c=='[')
{
c=getchar();
switch(c){
case 'A': /*fleche du haut*/
break;
case 'B': /*fleche du bas*/
break;
case 'C': /*fleche de droite*/
break;
case 'D': /*fleche de gauche*/
break;
}
}
break;
default:
/*autre touche*/
break;
}
}
return 0;
}
void mode_raw(int activer)
{
static struct termios cooked;
static int raw_actif = 0;
if (raw_actif == activer)
return;
if (activer)
{
struct termios raw;
tcgetattr(STDIN_FILENO, &cooked);
raw = cooked;
cfmakeraw(&raw);
tcsetattr(STDIN_FILENO, TCSANOW, &raw);
}
else
tcsetattr(STDIN_FILENO, TCSANOW, &cooked);
raw_actif = activer;
}
void cexit(void)
{
mode_raw(0);
putc('\n',stdout);
exit(0);
} |
Partager