Solved

Any Key problem in a Java App.

Posted on 1998-11-21
3
141 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now