I know how there are different ways of getting keyboard input such as conio.h
, but I want to learn how to use this method. the getkey
function uses stty
for gathering keyboard input.
char getkey()
{
char c;
system("/bin/stty raw");
system("/bin/stty -echo");
c = getc(stdin);
system("/bin/stty echo");
system("/bin/stty cooked");
return (c);
}
using it, here is how I would detect if the user pressed the a
key.
char c;
while (1)
{
switch (c = getkey())
{
case 'a': // stuff
}
}
the problem is that I don't know how to check for arrow keys. I tried printing the value of c
when I press any of the UP/DOWN/LEFT/RIGHT keys, but it shows me multiple numbers. how can I detect them?