hotkeys

P

patrick

I want to have a java application respond to keytype events.e.g. press z and
the application executes a z() method. But I want it to respond even if the
frame is minimized or does not have the focus. It is a swing application.

I have not succeeded in this with either addKeyListener() or with
AWTEventListener.

tia
patrick


getToolkit().addAWTEventListener(
new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
//do something here
}
},
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.FOCUS_EVENT_MASK
);
 
P

Pasturel Jean-Louis

patrick a écrit:
I want to have a java application respond to keytype events.e.g. press z and
the application executes a z() method. But I want it to respond even if the
frame is minimized or does not have the focus. It is a swing application.

I have not succeeded in this with either addKeyListener() or with
AWTEventListener.

tia
patrick


getToolkit().addAWTEventListener(
new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
//do something here
}
},
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.FOCUS_EVENT_MASK
);
It's impossible in pure Java. You must use JNI.
For windows look at fonction GetAsyncKeyState( int n) in win32 API .
 
P

patrick

Ok thanks. Id suspected that.
patrick

Pasturel Jean-Louis said:
patrick a écrit:
It's impossible in pure Java. You must use JNI.
For windows look at fonction GetAsyncKeyState( int n) in win32 API .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top