Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Last active November 15, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OneCent01/7281fc2e628b676b1da561bbbc8f3717 to your computer and use it in GitHub Desktop.
Save OneCent01/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
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