I am working on a console application written in Java. What I have to do is handle user keyboard input. When a long process in launched with our program in a terminal, the user must have the possibility to press 'q'
at anytime to stop the process (which is running on a separate thread).
I've tried several things :
- Running in another different thread something that read user input and throws an
InterruptedException
to the process' thread - Using JLine and its
ConsoleReader
- Using JLine and add a
TriggeredAction
linked to a keyboard key
But each time, I face the same problem : the user has to press ENTER
key, and I don't want that.
Thanks for help if you have any ideas, or the actual solution of my problem.
PS : Please, if you think this is impossible, don't answer. I know it's possible.