first time making a question.
What I want is a way of every time the user presses a key on the console certains actions take place. Like, as he types a word, I want at every keypress for a String formed by all the keys he's already pressed to be printed, concatenated to the newly pressed key. As in:
a
You typed: a
b
You typed: ab
c
You typed: abc
d
You typed: abcd
e
You typed: abcde
I'm trying to do this with the following code:
try (BufferedReader input = new BufferedReader(
new InputStreamReader(System.in, "UTF-8"))) {
char c = 0;
String s = "";
while( (c = (char) input.read() ) != 13) {
s += c;
System.out.println("You typed: " + s);
}
}
I get what I want, but just after I press the Enter key, not as every key pressed on the console:
foobar
You typed: f
You typed: fo
You typed: foo
You typed: foob
You typed: fooba
You typed: foobar
Thanks in advance.