I am writing a really basic program, but I have a problem. The following is a snippet of my code (this is a really stupid program, do not try to guess what I use it for.)
System.out.println("Please press the Return button a 1000 times."); for(int i = 1;i < 25;i++) { input.nextLine(); } System.out.println("Stop! Stop! Jeez, that was a joke! Do you think I'd make you press that button a 1000 times?"); try { Thread.sleep(3000); } catch (InterruptedException e) {} System.out.println("Let move on.");
What will be here is that the program asks the user to press the return button 1000 times, which ultimately the user will start spamming. The main problem is that after I declare that it was a joke, and he only needed to press 25 times, I would like to disable user input, since most likely the user will press the button several times before realize that I'm just a joke. But when thread.sleep is executed, user input is still active, which leads to a lot of problems.
So, is there a way to disable user input during sleep?
source share