wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Monitor Keyboard event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Monitor Keyboard event" Watch "Monitor Keyboard event" New topic
Author

Monitor Keyboard event

Andrew Ao
Greenhorn

Joined: Sep 10, 2001
Posts: 16
Hi,
i m looking for a way to monitor keyboard event in a text program - not GUI.
thank you,
-andrew
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
All java events are part of the AWT and are related to GUIs.
The best that you can hope for is to try and write some low level operating system dependant stuff. Perhaps you can "borrow" something from the event package and adapt it to what you want.
Of course an event has to be "against" something. Normally that is like a Frame or a TextField or a Button or something. So you are looking for a keyboard event against the Command Prompt?
I really have not a clue.
Andrew Ao
Greenhorn

Joined: Sep 10, 2001
Posts: 16
as far as i know, jave doesn't seem to have a method of "monitoring keystrokes". i think i might need to use jni.
thank you,
-aao
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hm, well you could extend an event structure, as Cindy mentioned, as save yourself the bother of going through JNI (which, by the way, won't help).
All you need to do is treat the class that gathers input from the keyboard as an event source. Being an event source means you register/deregister listeners, and on some change in your own state you construct an object that encapsulates the "event," and send it to your listeners in the form of a parameter.
If I get some time tonight, I'll write this out, but it's completely doable without a native construct.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Andrew Ao
Greenhorn

Joined: Sep 10, 2001
Posts: 16
hi:
sorry, but maybe i didn't make it clear. let me provide some background info.
i am writing the front end of an ordertaking app using java. due to its usage and need for fast entry, gui is NOT recommended. the user will be using a keyboard to enter orders and traverse around the application.
i was looking around, and try to find a way to intercept user keystroke. but System.in.readLine is a "blocking function." that's why i figure i might need to use native code to monitor keystrokes.
first, i should mention that my background is in the middle tier. so, i don't know much about UI. but here is what i am doing.
"recreate" text ui components using HMVC approach. monitor the keyboard input using native c code, and manage user's interaction using chain of command patterns.
if anyone has a better idea, please let me know. please drop a line at lovegokou@yahoo.com if you reply to this because this thread could get buried in javaranch.
regards,
-andrew
 
wood burning stoves
 
subject: Monitor Keyboard event
 
Similar Threads
what is the main difference between ...
red hat user interface 4 urgent
WA #1.....word association
Mac Mini anyone?
select: onchange or onclick?