Forums Register Login

listen to different keys simultaneously

+Pie Number of slices to send: Send
i have written a key listener for the keypressed event. the problem is that when a key is pressed and held the listener does not respond to any other key pressed. i want different keys recognized independently and simultaneously.how should i use multithreading and event handling in this case?
kindly note that i am using awt package in an applet.
waiting for your reply
kedar
+Pie Number of slices to send: Send
Hi, Kedar -
Threads won't help you -- because the AWT thread is the one responsible for handing out all of the key events -- but I think what you're trying to do is quite possible.
Look at the KeyListener interface again. If you implement the keyPressed and keyReleased methods, you will be able to figure it out when one key is pressed and another is also pressed before the first is released.
Dealing with the modifier keys (i.e., Ctrl, Shift, Alt) is even easier. InputEvent (the superclass of KeyEvent) has methods isShiftDown(), isAltDown() and so on.
One caveat here: I tested this in WinNT, JDK 1.2. Obviously, there might be bugs in other configurations (i.e., Java 1.1 in an applet) that could prevent it from working properly...
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 836 times.
Similar Threads
listening to two keys simultaneously
listening to two keys simultaneously
simple question about swing?
listening to two keys simultaneously
working on celphone's keypad
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:54:37.