awt.KeyEvents, advanced question.

How do you capture KeyEvents system- wide?

Some cool java 1.2 (or later) code:

Toolkit.getDefaultToolkit().addAWTEventListener (this, AWTEvent.KEY_EVENT_MASK);

...

publicvoid eventDispatched(AWTEvent event)

{

//...event captured! I can react on it here!

}

This nice piece of code is java 1.2 and hence can抰 be used by my applet. (My users are stuck with a browser that only supports java 1.1.8, and they don抰 want to download any plug-in)

How do I do this in java 1.1.8?

My approach so far has been to use addKeyListener() recursively on the applet and all its awt.Component抯. It works ok but it is a little messy, especially when components are added or removed (Then I have to detect it and perform the recursive adding of KeyListeners again.). Is there any other way?

[987 byte] By [Ragnvalda] at [2007-9-19]
# 1
I suggest you use single ContainerListener and KeyListener instance to handle the add and remove component and key event.
angusedisona at 2007-7-8 > top of java,Core,Core APIs...
# 2
Thx. I followed your advice. The code gets cleaner and better that way, and the few bugs I had dissapeared!
Ragnvalda at 2007-7-8 > top of java,Core,Core APIs...