1

I've been trying to write a Java console program that can act upon arrow keys. I came across JLine library that claims to be able to do this.

I've tried a few times to use the JLine library to accomplish my goal, but have been unsuccessful in doing so.

ConsoleReader reader = new ConsoleReader(System.in, new PrintWriter(System.out)); Despite using ConsoleReader.readVirtualKey(), it still waits for enter key press.

I have also tried using

UnixTerminal terminal = (UnixTerminal) Terminal.setupTerminal();
terminal.readVirtualKey(System.in);

But this doesn't work either. It always waits for Enter key and does not show the arrow keys that I pressed before pressing the Enter key.

Could someone help me with this?

Guru Prasad
  • 4,053
  • 2
  • 25
  • 43

1 Answers1

1

A bit late perhaps, but I'm experimenting myself with jline.

This works for me:

ConsoleReader cr = new ConsoleReader();
String line = cr.readLine("type something: ")

It will probably not work if you run the program in an IDE though, e.g. it doesn't work in IntelliJ for me.

DanneJ
  • 358
  • 1
  • 9