Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Monitoring java console for key presses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Monitoring java console for key presses" Watch "Monitoring java console for key presses" New topic
Author

Monitoring java console for key presses

S. Lohi
Greenhorn

Joined: May 21, 2004
Posts: 11
Hello.

I have a problem with my java program. I'm trying to build an internet radio client for my server machine. The problem is how I'm gonna give input to the program. The server box does not have a monitor, so I'm gonna have to give the input through keyboard "blind". For this reason it would be great if pressing only one key would do the trick instead of pressing the key and then inputting it with enter.

So, the question is: can you monitor the key presses in the normal console window like you can in swing components with KeyListener? If yes, how? If no, is there a workaround? My server has no graphical interface installed so it can't include swing or any other graphical UI component. Any kind of working solution goes since the only thing the interface part of the program has to do is detect the key presses, nothing else.

Edit: My server runs a Red Hat Linux.

Thanks for your help.
[ May 19, 2005: Message edited by: S. Lohi ]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
You might try System.in.read(), but I'm not sure if it will work without pressing enter.

My recommendation would be to control it over the network. Have it open a socket and listen, then you can send it simple commands from one of your other machines.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Monitoring java console for key presses
 
Similar Threads
How to issue command in Java program
Creating a command prompt is swing
JTable & Keyboard Shortcuts
Suggestions required for solving a Java problem
how to take and check input in Java