Detect a key press in console
You can't detect an event in the command line environment. You should provide a GUI, and then you can use the KeyListener
class to detect a keyboard event.
Alternatively you can read commands from standard input and then execute a proper function.