Last active
November 15, 2019 08:16
-
-
Save xfateless/7281fc2e628b676b1da561bbbc8f3717 to your computer and use it in GitHub Desktop.
Reads character input from the user; handles arrow keys, converting them to their equivalent WASD character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char read_input_char() | |
{ | |
char c; | |
c = getch(); | |
if (c == '\033') { // if the first value is esc | |
c = getch(); // skip the [ | |
switch(c = getch()) { // the real value | |
case 'A': | |
// code for arrow up | |
return 'w'; | |
case 'B': | |
// code for arrow down | |
return 's'; | |
case 'C': | |
// code for arrow right | |
return 'd'; | |
case 'D': | |
// code for arrow left | |
return 'a'; | |
} | |
return c; | |
} else { | |
return c; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment