It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Monitoring java console for key presses" Watch "Monitoring java console for key presses" New topic

Monitoring java console for key presses

S. Lohi

Joined: May 21, 2004
Posts: 11

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, 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.
I agree. Here's the link:
subject: Monitoring java console for key presses
It's not a secret anymore!