Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > question about console Input

Reply
Thread Tools

question about console Input

 
 
layman
Guest
Posts: n/a
 
      01-24-2005
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
 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      01-24-2005
On 24 Jan 2005 01:27:11 GMT, layman wrote:
> 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/...697a1d029dd808

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

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-25-2005
On 24 Jan 2005 10:59:34 +0100, Gordon Beaton wrote:

> 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.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      01-25-2005
On Tue, 25 Jan 2005 09:36:19 GMT, Andrew Thompson wrote:
> On 24 Jan 2005 10:59:34 +0100, Gordon Beaton wrote:
>> 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.


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

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

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      01-25-2005
On 25 Jan 2005 11:11:36 +0100, Gordon Beaton wrote:

> On Tue, 25 Jan 2005 09:36:19 GMT, Andrew Thompson wrote:
>> On 24 Jan 2005 10:59:34 +0100, Gordon Beaton wrote:
>>> You seem to be using a Unix-like operating system.

>>
>> Out of curiosity, what makes you say that?

...
> 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>

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      01-25-2005
Gordon Beaton <(E-Mail Removed)> scribbled the following:
> On 24 Jan 2005 01:27:11 GMT, layman wrote:
>> 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/...697a1d029dd808


> 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 ((E-Mail Removed)) ------------- 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
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      01-25-2005
On 25 Jan 2005 19:54:46 GMT, Joona I Palaste wrote:
> Actually, it's Windows, not Unixen, that generally tends to have a
> getch() function implemented.


Did anyone suggest that wasn't the case?

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      01-25-2005
Gordon Beaton <(E-Mail Removed)> scribbled the following:
> On 25 Jan 2005 19:54:46 GMT, Joona I Palaste wrote:
>> Actually, it's Windows, not Unixen, that generally tends to have a
>> getch() function implemented.


> 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.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Roses are red, violets are blue, I'm a schitzophrenic and so am I."
- Bob Wiley
 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      01-25-2005
Joona I Palaste <(E-Mail Removed)> scribbled the following:
> Gordon Beaton <(E-Mail Removed)> scribbled the following:
>> On 25 Jan 2005 19:54:46 GMT, Joona I Palaste wrote:
>>> Actually, it's Windows, not Unixen, that generally tends to have a
>>> getch() function implemented.


>> 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.


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".

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Ice cream sales somehow cause drownings: both happen in summer."
- Antti Voipio & Arto Wikla
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      01-26-2005
On 25 Jan 2005 21:43:12 GMT, Joona I Palaste wrote:
>> 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".


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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading console output and writing to console jan.rebada@gmail.com C++ 5 03-04-2008 09:00 AM
Preventing the console window from closing when writing a console program in C++ Miktor C++ 7 08-09-2005 09:22 PM
Re: console mp3->wav decoder for $indows or GUI one which supports console Serge Terekhoff Python 0 06-30-2003 12:36 PM
Re: console mp3->wav decoder for $indows or GUI one which supports console Egor Bolonev Python 0 06-30-2003 10:43 AM
Re: console mp3->wav decoder for $indows or GUI one which supports console Ben Finney Python 2 06-30-2003 05:43 AM



Advertisments