question about console Input

L

layman

Hello group,
I wonder if there's any equivalent to C's getch() in java, i.e to
fetch a character from the console immediately after the user typed it,
without pressing the "Enter" key.
Any solution or suggestion is welcome, thank you!





layman
 
G

Gordon Beaton

Hello group,
I wonder if there's any equivalent to C's getch() in java, i.e to
fetch a character from the console immediately after the user typed it,
without pressing the "Enter" key.
Any solution or suggestion is welcome, thank you!

You seem to be using a Unix-like operating system. Here's a
non-portable solution that uses stty to change the input mode:

http://groups-beta.google.com/group/comp.lang.java.programmer/msg/df697a1d029dd808

After that, you can use System.in.read() to read single characters.

/gordon
 
A

Andrew Thompson

You seem to be using a Unix-like operating system.

Out of curiosity, what makes you say that? I can determine
no clue from the headers or post as to the OP's OS, so I must
be looking for the wrong things.
 
G

Gordon Beaton

Out of curiosity, what makes you say that? I can determine no clue
from the headers or post as to the OP's OS, so I must be looking for
the wrong things.

The presence of "X11" in the User-Agent string:

User-Agent: Mozilla Thunderbird 1.0 (X11/20041206)

/gordon
 
A

Andrew Thompson

...
The presence of "X11" in the User-Agent string:

Thanks. That was bugging me!

And now, I better try and bow out of this technical
discussion as gracefully as I can manage.

<insert>
Sound of splintering timbers/falling masonry/breaking glass.
</insert> ;-)
 
J

Joona I Palaste

You seem to be using a Unix-like operating system. Here's a
non-portable solution that uses stty to change the input mode:

After that, you can use System.in.read() to read single characters.

Actually, it's Windows, not Unixen, that generally tends to have a
getch() function implemented.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You have moved your mouse, for these changes to take effect you must shut down
and restart your computer. Do you want to restart your computer now?"
- Karri Kalpio
 
J

Joona I Palaste

Did anyone suggest that wasn't the case?

Someone said "You seem to be on a Unix-like system" which I took to mean
they thought the OP was using Unix.
 
J

Joona I Palaste

Someone said "You seem to be on a Unix-like system" which I took to mean
they thought the OP was using Unix.

Clarifications:
(1) That someone was you (not talking to myself of course).
(2) My statement in my earlier post is a bit of a tautology. I meant
"...which I took to mean the OP was referring to a Unix function".
 
G

Gordon Beaton

Clarifications:
(1) That someone was you (not talking to myself of course).
(2) My statement in my earlier post is a bit of a tautology. I meant
"...which I took to mean the OP was referring to a Unix function".

I did say that (because I did think the OP was using Unix), but I made
no statements about the "c-function" he mentioned.

As I indicated in an earlier response to Andrew, I came to that
conclusion based on his User-Agent setting, and used that to justify
suggesting that particular platform-specific solution.

/gordon
 

T.N

Joined
Sep 12, 2007
Messages
1
Reaction score
0
please could any one help to replace getch()

please please any one
could any one tell me how can i replace getch() with proper instruction in
JAVA
please that is so urgent
pleeeeeeeeeeeeeeeeeeeeeeeeeease

my e_mail :
(e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top