Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mary Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example:
>a
a
ie: if a user entered a char 'a', the screen will display it 'a' immdiately.
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic