You're answer is simple:
You can't do that!
Because you're using a command-line window. In command-line there is no listeners like KeyListener
or MouseListener....
.
If you want to do so, leave the command-line and go learn Swing
in java.
See this question: How to get input without pressing enter every time?