Question

I am creating a very simple program, asking the user to guess words. Guessing words works just with Scanner and System.out.println(), so its very simple and no user interface is needed.

The guessing of words is done with eclipse. Now I need to add a function, which will allow the user to exit the "program" anytime by clicking CTRL+z and when they do that I'll need also to print out possible words they could've have guessed.

But I do not know how to add the CTRL+z exit function. Can anyone suggest anything on how to ? The word guessing is a loop.

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top