• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read only one char from the console

 
saran sadaiyappan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to read only one char from the keyboard.i.e.even if i press the keys ABC only A should be displayed and not B and C.ANy Idea?
 
Ramaswamy Narayanan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please try with KeyListener
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyListener only works if you have a GUI component which has focus. Since Java is cross-platform and some of those platforms may not have consoles (or keyboards for that matter, JavaPhone anyone?) the console capabilities are pretty weak. You can read a single character with InputStream.read(), but you still have to hit "enter" on the end of the line on the console. I once got around this limitation by using JNI. For anything but trivial programs (or UNIX-style utilities), I recommend choosing a real GUI over the console.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!