-1

I am an AP Computer Science student who is trying to write a console-based text editor. My teacher taught me how to read input using Scanner(System.in), but in a text-editor, you need to get input directly from the keyboard. How do I gain access to keystrokes without using the Scanner class, or a similar parallel? For example, BufferReader(new InputStreamReader(System.in))

EDIT: My point was how read without waiting for user to press enter (otherwise users couldn't add text in real time)

EDIT: Why are you saying my question is a duplicate of that question? I explicitly asked for a method of getting input without waiting fo ruser to press enter. The answers to that other question do not resolve that at all!

  • possibly related [Is it possible to print text that can be edited by the user (for console programs)?](http://stackoverflow.com/questions/1552156/is-it-possible-to-print-text-that-can-be-edited-by-the-user-for-console-program), [Java: how can I modify console output?](http://stackoverflow.com/questions/6704002/java-how-can-i-modify-console-output) – chickity china chinese chicken Feb 14 '17 at 17:47
  • If you're looking to read input character-by-character, you can use [this answer](http://stackoverflow.com/questions/1066318/how-to-read-a-single-char-from-the-console-in-java-as-the-user-types-it). If you're looking for reading arbitrary keyboard input (such as arrow keys), you'll probably need to drop down to the JNI. – saagarjha Feb 14 '17 at 17:49
  • @cricket_007 It appears that Null-Terminator is using the console. – saagarjha Feb 14 '17 at 17:50

1 Answers1

-1

You can use this :

 System.out.print("Please enter your String :\t");
String sentence = scanner.nextLine();
hicham abdedaime
  • 346
  • 2
  • 15