Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait for enter key to be pressed

Status
Not open for further replies.

De8o

Technical User
Sep 26, 2000
70
US
I'm having a problem with the code below.

What I want to do is wait for the RETURN key to be pressed before continuing.

char listen = x;
while (listen != '\r'){
listen=keyboard.readChar(); //defined method (working)
}

does anybody have an easy way to do what I want.

Thanks in advance,
De8o
 
Hi De8o:

It depends directly on the implementation of the readChar() method. If you want to ignore other keys pressed, you can simply do the following:

BufferedReader d
= new BufferedReader(System.in);
try{
d.readLine();
}
catch(IOException e){}


Since the readLine method returns when the user press enter.

If you care about the other characters pressed, then yo must check the correct unicode representation of the carriage return character.

Hope it helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top