Reputation: 31
I'm looking to print text on a line that is AFTER where the user is inputing their text.
String userInput;
System.out.println("Hello");
userInput = In.getString();
//I want a System.out.print(""); right here, but I want it to appear while
//the user is still typing their input.
Print: "Hello"
User is getting input
Print "I am printing this at the same time that the user is typing"
Upvotes: 3
Views: 491
Reputation: 3755
You can put console into raw mode. There is no built-in platform-independent way of getting there. This might be a solution you can implement,
Non blocking console input in Python and Java
got it from here. There are more solutions in there that might be helpful
Upvotes: 0
Reputation: 2086
As mentioned in the comments, keystrokes cannot be captured in raw java console applications.
His could be do e using gui applications like using AWT/Swing GUI
.
Since this could be an overkill for your problem, you should know that java suports editing of console outputs in a way.
E.g. if the current output has hello
, printing \b
character will erase one character from console and it will look like hell
.
Perhaps you can think in these lines and build your functionality.
Upvotes: 1