Skip to content

Instantly share code, notes, and snippets.

@sleiner
Created January 16, 2015 16:30
Show Gist options
  • Save sleiner/855afffacf8ef672c8fe to your computer and use it in GitHub Desktop.
Save sleiner/855afffacf8ef672c8fe to your computer and use it in GitHub Desktop.
#include <conio.h>
char arrowkey_input() {
char input_ch = _getch();
// detect arrow keys (idea from http://stackoverflow.com/questions/10463201/getch-and-arrow-codes/11432632#11432632)
if (input_ch == -32) { // prefix for arrow keys
switch (_getch()) { // the real value
case 72: // up
return 'u';
case 80: // down
return 'd';
case 77: // right
return 'r';
case 75: // left
return 'l';
}
}
else
return input_ch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment