How to read chars without <enter> key from input?

Hi all.

I have read many forums but I still haven't figure it out how to read characters from the console input without having the user to type the return key <enter>.

What I have found is that I have to make a combination of KeyListener or KeyAdapter using a Writer.

The thing is that I haven't found a way to transform the inputSystem.in into a Writer and then as there are no GUI, I quite don't get how to use the KeyListener from the console.

What I suppose is that once the input stream has been wrapped into a Writer, I would have to catch the key strokes and depending on what I want, either take some action or simply pass the character to the console.

A good example would be like a simple implementation of a program that tells the user, "Type any key to continue" (and the user does not have to type enter for that).

Thx in advance.

[903 byte] By [@lphazygmaa] at [2007-11-26 14:44:21]
# 1

I have basically no experience with trying to do this, so someone correct me if I'm wrong, but you'll need to do more than wrap System.in in another Writer. The input from the console is still going directly to System.in, bypassing the wrapper. You'll need to rewire the console to send it's input to the wrapper, and i don't know of any way to do that.

hunter9000a at 2007-7-8 8:32:03 > top of Java-index,Java Essentials,Java Programming...
# 2

You are mixing things up. First of all, console-based applications and Swing-based application are different animals. You seem to want to write a console-based app (why, oh why?) so Swing things like KeyListener are out.

You may want to check out JCurses: http://sourceforge.net/projects/javacurses/

I don't know anything about it, but "curses" was a standard UNIX library for doing what you want to do, in C.

DrLaszloJamfa at 2007-7-8 8:32:03 > top of Java-index,Java Essentials,Java Programming...