Capturing all KeyEvents in the system

From: Kannan S (kannan123_at_gmail.com)
Date: 10/25/04


Date: 25 Oct 2004 11:34:25 -0700

Hi,

I am using jdk1.1.18 and jfc-swing-1.1.1 in my appication. This is an
embedded system running (what I think is) JWorks on VxWorks, which
(again, I guess) is based on the combination I mentioned above and I
dont have the option of upgrading to later java versions.

I want to capture all the KeyEvents in the system (lowlevel ones like
KEY_RELEASED, not just ActionEvents or KEY_TYPED) , irrespsective of
which component has the focus currently. The root container is a
JWindow with a custom (Drawer) layout.

In jdk1.4, I would have used any of the following:

1. Toolkit.addAWTEventListener(new MyAWTListener());
2. FocusManager.setCurrentManager(new MyFocusManager());
3. setVisible(true) on the glasspane of my JWindow, capture events and
re-dispatch them.

In fact, #2 sort of works in jfc-swing-1.1. But I dont get low level
events like KEY_RELEASED. If the component with focus is a text-aware
one (like JTextField), then I get both KEY_PRESSED and KEY_TYPED, but
not KEY_RELEASED. But If the component in focus is a JButton, I get
only KEY_TYPED.

I have 3 questions:

a. Is there an equvalent of #1 in jdk1.1..8?

b. Is there a way to make #2 give me KEY_RELEASED events?

c. Would #3 above work? How do I do it? Again, I dont seem to be
getting KeyEvents at all, even after doing
enableEvents(AWTEvent.KEY_EVENT_MASK) on MyJPanel. I get all the mouse
events, though. But then, how do I re-dispatch events?

I have searched through this forum and google a lot. But couldn't find
any solution.

Thanks


Quantcast