0

Possible Duplicate:
How to read a single char from the console in Java (as the user types it)?

I'm programming in Java and I was wondering if they're was a way to "wait" until a button is pressed before proceeding to the next part of the program. I am running this in Terminal. i.e.

Scanner in = new Scanner(System.in);
.
.
.
System.out.print("Something");
/* Wait until a button has been pressed */ 
System.out.println("Something Else");

Something like in.next() would wait until you've press something then press enter. Is there a way you could wait until any button has been press (or the mouse clicked?) and then proceed to the next line. Preferably having the input not echoed to the screen (if that's possible).
So the output would be: Something Something Else

Thanks for all your time Any help is appreciated.

Community
  • 1
  • 1
  • This method is for Swing: [Java Tutorials - How to write a Key Listener](http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html) – Keppil Nov 02 '12 at 05:41

1 Answers1

1

One way would be to set a Keyboard / Mouse Hook.

You can use Jnativehook to do that:

JNativeHook is a library to provide global keyboard and mouse listeners for Java. This will allow you to listen for global shortcuts or mouse motion that would otherwise be impossible using pure Java. To accomplish this task, JNativeHook leverages platform dependent native code through Java's native interface to create low level system wide hooks and deliver those events to your application.

Another way would be to write a KeyListener to capture keyboard input, take a look here

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130