How to detect keyboard arrow keys input?

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.

section 1.5 on this page ??

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...

Forgot to mention that I'm using Putty to connect to my Arduino... and sometimes I'm also using screen from my MAC OS.

I can catch ESC with case 27: and return with case 13: so I'm hoping to use something similar to catch the UP and DOWN arrow :slight_smile:

If that is not possible... what's the best and/or most common keys I can use to go UP and DOWN?

Easy to check, just use a program that returns everything :slight_smile:

void setup(){
  Serial.begin(115200);
}

void loop(){
  if(serial.available()){
    in = Serial.read();
    
    Serial.print(F("Input detected: '"));
    Serial.print(in);
    Serial.print(F("' 0x"));
    Serial.print(in, HEX);
  }
}

But because there is no ASCII code for it I doubt it.

Markino76:
If that is not possible... what's the best and/or most common keys I can use to go UP and DOWN?

for the reasons pointed out, no it is not possible using simple serial communication.

just pick some keys on your keyboard...

U for up, D for down ?

I'm not sure about Putty, but Tera Term sends ISO escape sequences for the arrow keys.