How to intercept a key stroke in a Java console app?

C

chirs

How to intercept a key stroke in a Java console application? The key
strokes are entered in the DOS window. I need to discard all the key
strokes except the Enter key. When a use type other keys, nothing
will happen. When he presses the Enter key, the program will
continue.

Thank you very much.

Chris
 
C

Chris Smith

chirs said:
How to intercept a key stroke in a Java console application? The key
strokes are entered in the DOS window. I need to discard all the key
strokes except the Enter key. When a use type other keys, nothing
will happen. When he presses the Enter key, the program will
continue.

If you use BufferedReader.readLine() and ignore the actual contents of
the return value, you can accomplish this. If you're looking for a way
to prevent the keys from appearing on the screen, though, then I'm
afraid you've exceeded the capabilities of pure Java. Java is not
designed for writing console-mode user interfaces, and very few non-
trivial things are possible if you try.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top