Is there in Java the possibility to get what a user press “when it presses”
and not when he hits return?
So, for example, if a user hit ABC and then hit Ctrl+Z I want that the program ends there
(end of stream reached) and not, after, when he presses return.
Windows doesn’t actually end the stream when you press Ctrl+Z; you can continue to edit the line and the application will only see the end of the stream when you press Return.
This is slightly different to Unix where Ctrl+D will send the current buffered line to the application (without a newline) and the application will only perceive the end of the stream when you send an empty buffer by pressing Ctrl+D either after a Return or after another Ctrl+D.
Edit: On Windows, you might be able to use the SetConsoleMode function to allow you to read single characters. I’m not sure how you would call it though; there appear to be three choices: