Reputation: 21
I am creating a game, and just to get the logic down I am only using the console window to test the process. I am prompting the user to hit either the 'd' or the 'p' key without requiring to press the Enter key. If the user presses either one it will branch off to its subroutine. How do I go about waiting for the input of a single key?
This is in Java. Sorry for the confusion
Upvotes: 2
Views: 8170
Reputation: 307
It sounds like you want to read a keypress without waiting for an "enter" or newline. Unfortunately this isn't really possible in Java, as detailed in this thread. I wish I could help you more, but there aren't really any portable ways of doing it.
Upvotes: 2
Reputation: 502
Include the below line where your program want to wait to get input from user.
DataInputStream input = new DataInputStream(System.in); String string = input.readLine();
For more information refer the below site
http://www.roseindia.net/java/java-get-example/java-get-user-input.shtml http://www.daniweb.com/software-development/java/threads/85435
Upvotes: 0