Solved

Any Key problem in a Java App.

Posted on 1998-11-21
3
143 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
basic hardware to learn oop advanced design patterns 3 88
Securing Jmx Console and web console 2 64
Java Timer (static) 9 36
factorial example 4 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

930 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

14 Experts available now in Live!

Get 1:1 Help Now