|
@ -0,0 +1,72 @@ |
|
|
|
|
|
#include<stdio.h> |
|
|
|
|
|
#include<ctype.h> |
|
|
|
|
|
#include<stdlib.h> |
|
|
|
|
|
#include<unistd.h> |
|
|
|
|
|
#include<fcntl.h> |
|
|
|
|
|
#include<termios.h> |
|
|
|
|
|
int kbhit(void); |
|
|
|
|
|
char getch(void); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*int main(int argc, char ** argv){ |
|
|
|
|
|
while(1){ |
|
|
|
|
|
getInput(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
void getInput(){ |
|
|
|
|
|
if(kbhit()){ |
|
|
|
|
|
char key= getch(); |
|
|
|
|
|
if(key=='w'){ |
|
|
|
|
|
printf("W"); |
|
|
|
|
|
} |
|
|
|
|
|
else if(key=='a'){ |
|
|
|
|
|
printf("A"); |
|
|
|
|
|
} |
|
|
|
|
|
else if(key=='s'){ |
|
|
|
|
|
printf("S"); |
|
|
|
|
|
} |
|
|
|
|
|
else if(key=='d'){ |
|
|
|
|
|
printf("D"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//khbit und getch aus dem Internet |
|
|
|
|
|
int kbhit(void){ |
|
|
|
|
|
struct termios oldt, newt; |
|
|
|
|
|
int ch; |
|
|
|
|
|
int oldf; |
|
|
|
|
|
|
|
|
|
|
|
tcgetattr(STDIN_FILENO, &oldt); |
|
|
|
|
|
newt = oldt; |
|
|
|
|
|
newt.c_lflag &= ~(ICANON | ECHO); |
|
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &newt); |
|
|
|
|
|
oldf = fcntl(STDIN_FILENO, F_GETFL, 0); |
|
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); |
|
|
|
|
|
|
|
|
|
|
|
ch = getchar(); |
|
|
|
|
|
|
|
|
|
|
|
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); |
|
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, oldf); |
|
|
|
|
|
|
|
|
|
|
|
if(ch != EOF) |
|
|
|
|
|
{ |
|
|
|
|
|
ungetc(ch, stdin); |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char getch(void) |
|
|
|
|
|
{ |
|
|
|
|
|
char c; |
|
|
|
|
|
system("stty raw"); |
|
|
|
|
|
c= getchar(); |
|
|
|
|
|
system("stty sane"); |
|
|
|
|
|
return(c); |
|
|
|
|
|
} |
|
|
|
|
|
|