Hi guys,
I've implemented a simple menu over the Serial and I'm trying to use the arrow keys of the keyboard to move up and down in the menu items but I can't get the correct keyboard input.
This is the snippet where I use '[' and ']' to move up and down and it works.... what char have I to catch for the arrows keys?
if (!Serial.available()) return false;
switch (Serial.read()) {
case 27: // ESC
case '0':
// No Selection
break;
case '[': // Here I want to use UP Arrow Key
// Move UP
break;
case ']': // Here I want to use DOWN Arrow Key
// MOve DOWN
break;
}
Simply said, you can't. The arrows are not characters so they don't result in Serial output. At least not for Serial Monitor (an most terminal programs). If you want that you'll have o make your own computer program to run and to send some character to the Arduino.
The answer to this question depends on what operating system and programming language you are using. There is no ASCII code for these arrow keys. The operating system detects you hit an arrow key and triggers an event that programs can capture.
this is why certain games in the early days used keys like E,D,X and S (notice their arrangement on your keyboard) to move about.
So, as pointed out, your PC-side program has to do an interpretation and send values accordingly... or you can use four adjacent keys on your keyboard...