Solved

Any Key problem in a Java App.

Posted on 1998-11-21
3
147 Views
Last Modified: 2010-03-30
How can I capture a character from the user's key press without the user having to press the 'enter' key. Similar to the getch function in Turing.

This question was asked, but wasn't correctly solved.

// suggested on expert net
char ch;
ch = System.in.read();

still needs the return key to be pressed.

Nobody seems to know this.. and it seems so simple.
0
Comment
Question by:tin_pham
3 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 1227992
This is perfectly correct. It assume that you are inconsole context and here the InputStream in is buffered meaning that the Return key must be pressed.
   In which context do you want a solution? Concole context or have you some GUI on the screen?
0
 

Accepted Solution

by:
revferret earned 100 total points
ID: 1227993
You can implement the java.awt.event.KeyListener class.

This class has 3 methods:
public void keyPressed(java.awt.event.KeyEvent kevent);
public void keyTyped(java.awt.event.KeyEvent kevent);
public void keyReleased(java.awt.eventKeyEvent kevent);

This is how I do it and it seems to work.
0
 

Author Comment

by:tin_pham
ID: 1227994
Thanks to everybody who attempted to solve this. I've come to the conclusion that it's not possible because of the way Java reads the input stream.

I cannot use the AWT because this is a java Application not an Applet.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question