In my code, I am stopping the thread after printing a character from a string in order to write the string letter by letter.
When the thread is stopped, meaning until the string is finished being printed, any key presses a user presses are not printed on the screen nor discarded.
However, if there is a readLine() function after that, it picks up those stored key presses into the System.in input stream, and if the user presses enter, those key presses get instantly sent as an input.
So my question is, is it possible to clear the System.in input stream and cancel those stray key presses?
My code:
val foo = "Hello World"
for (char in foo) {
print(char)
Thread.sleep(40)
}
val input = readLine()!! //ensure not-null
println(input)
Help is much appreciated.
Kotlin help is preferred, but Java answers will work just as fine.