0

I can read console input by:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String in = br.readLine();

The goal is to show last console input by pressing key "Up". When pressed console shows ^[[A symbols. The code below does not detect when key "Up" is pressed:

switch (in) {
  case "^[[A"://Key up.
   //Do something - print previous input.
   break;
   //...
}

System.out.println(in);
Ernestas Gruodis
  • 7,563
  • 12
  • 45
  • 104
  • 2
    Possible duplicate of [Detecting and acting on keyboard direction keys in Java](https://stackoverflow.com/questions/572001/detecting-and-acting-on-keyboard-direction-keys-in-java) – Zabuzard Jun 17 '18 at 16:22
  • 1
    https://stackoverflow.com/questions/4005574/java-key-listener-in-commandline possible duplicate – Coder-Man Jun 17 '18 at 16:23
  • 1
    The string `"^[[A"` with the encoding obviously does not represent the same byte sequence than the arrow-input bytes. Read the linked duplicates, the match won't work. – Zabuzard Jun 17 '18 at 16:25

0 Answers0