From bbcbb2e8375d4d8bb2631f49eab2b7f8ecce5533 Mon Sep 17 00:00:00 2001 From: fdai7184 Date: Wed, 8 Feb 2023 21:19:04 +0100 Subject: [PATCH] testArrowInput funtionality into getInput --- src/input.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/input.c b/src/input.c index 95cad7d..c353ab7 100644 --- a/src/input.c +++ b/src/input.c @@ -10,34 +10,14 @@ char getch(void); /*int main(int argc, char ** argv){ while(1){ - //getInput(); - testArrowInput(); - } - + getInput(); + } }*/ void getInput(){ - if(kbhit()){ + 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"); - } - } -} - -void testArrowInput(){ - if(kbhit()){ - char key1 = getch(); - if(key1 == '\033'){ + if(key == '\033'){ getch(); char key = getch(); if(key=='A'){ @@ -53,13 +33,29 @@ void testArrowInput(){ printf("left"); } } - else if(key1=='q'){ - printf("Quit"); + else{ + if(key=='w'){ + printf("W"); + } + else if(key=='a'){ + printf("A"); + } + else if(key=='s'){ + printf("S"); + } + else if(key=='d'){ + printf("D"); + } + else if(key=='q'){ + printf("quit"); + } } + } } + //khbit und getch aus dem Internet int kbhit(void){ struct termios oldt, newt;