0

Is there anything simple like ReadKey from .NET/Mono for Java? I need to read input from the console, but I also need to be notified that user is typing (aka there is some input in the prompt, but user has not yet submitted the line by pressing enter key).

In .NET you can scan for keys by calling blocking System.Console.ReadKey but I was unable to find anything like that in Java.

I can't understand there is no way to do such a simple and elementary thing. Or am I missing something?

Update

I tried experimenting with jline but was unable to make it working (at least not on MacOS, which is my base system. I am not sure whether it works on other platforms).

Jline seems to me as absolutely unstable library, that is changing absolutely everything from version to version.

Does anybody have working example with jline, that is able to respond on console input? I supposed that readVirtualKey should do the job, but it's been removed in last versions of jline and when I tried it with older versions, it worked like regular System.in.read()

Martin Macak
  • 3,507
  • 2
  • 30
  • 54
  • You may want to check http://stackoverflow.com/questions/1066318/how-to-read-a-single-char-from-the-console-in-java-as-the-user-types-it. – M A Mar 07 '15 at 15:08
  • I have already read those threads and it seems that there is a lot of confused talking there but no real facts. I don't understand the fact that for example Mono is capalble of doing such a thing and retain it's platform independence (Java is still provided for each platform with native bridges and libraries), so that's no excuse for me in that. – Martin Macak Mar 07 '15 at 17:31
  • This is duplicate of http://stackoverflow.com/questions/4531560/get-key-press-without-pressing-enter-in-console and http://stackoverflow.com/questions/4531791/execute-stty-raw-command-in-same-terminal so I am adding a request for close. – Martin Macak Mar 08 '15 at 20:26

0 Answers0