aspose file tools*
The moose likes Java in General and the fly likes How can I read a single character from keyboard as soon as typed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can I read a single character from keyboard as soon as typed?" Watch "How can I read a single character from keyboard as soon as typed?" New topic
Author

How can I read a single character from keyboard as soon as typed?

Mary Smith
Greenhorn

Joined: Aug 16, 2001
Posts: 4
For example:
>a
a
ie: if a user entered a char 'a', the screen will display it 'a' immdiately.
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Can you be a bit more specific?
Are you using an Servlet (don't think so...) , an Application, an Applet, something else??
If you are using an applet, then this is an example code:

Cheers, Erik
Martin Rennix
Ranch Hand

Joined: Sep 30, 2001
Posts: 34
Here's the answer to the same question at the JavaFAQ (http://www.afu.com/intro.html):
Q. Is there a way to read a char from the keyboard without having to type carriage-return?
A.You can do this in a GUI (e.g. in a text component). There is no pure Java technology way to do character-by-character I/O without using a GUI. Bug id #4075058 has been filed to request this feature.
On Unix, if you enter 'stty cbreak' before running your java program, System.in will return character-by-character input. If you want to set this up from within a Java program, it is a bit tricky, since when the JVM executes a Runtime process, the process is not tied to any terminal.
 
Consider Paul's rocket mass heater.
 
subject: How can I read a single character from keyboard as soon as typed?