Hi,
Using Java 1.5.0_06-b05.
XP SP2
I attached a KeyListerner to a component to specifically monitor modifer key
events (Shift/Alt/Ctrl keys).
Using simple code I can pick up the keyPressed() and keyReleased() events
fine, but I noticed some weird behaviour with the Alt key.
When pressing the Alt key, it triggers a keyPressed event and then a
subsequent keyReleased event when I release the key (as expected). But when
I hit Alt a second consecutive time, it does not trigger a keyPressed event,
but it does trigger the subsequent keyReleased event when released. When I
press a third consecutiv time, it behaves correctly (triggers both pressed
and released events). In summary, every second consecutive pressing of Alt
fails to trigger a keyPressed event, but all keyReleased events are
triggered.
All other keys (Shift and Ctrl) seem to behave normally.
Is this normal behaviour for the Alt key or is it a potential bug of the JVM
or OS???
Thanks!
Knute Johnson - 02 Jun 2006 06:22 GMT
> Hi,
>
[quoted text clipped - 22 lines]
>
> Thanks!
Sure looks like a bug to me! I get exactly the same behavior. What OS
are you using? I tested it on XP SP2.
import java.awt.*;
import java.awt.event.*;
public class test2 {
public static void main(String[] args) {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
TextField tf = new TextField("text field");
tf.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
System.out.println("keypressed");
}
public void keyReleased(KeyEvent ke) {
System.out.println("keyreleased");
}
});
f.add(tf);
f.pack();
f.setVisible(true);
}
}

Signature
Knute Johnson
email s/nospam/knute/
Knute Johnson - 02 Jun 2006 06:46 GMT
It works correctly on FC5 with Sun jdk1.5.0_06.
--
knute...
Luc The Perverse - 02 Jun 2006 06:50 GMT
> Is this normal behaviour for the Alt key or is it a potential bug of the
> JVM or OS???
Yes this is normal and correct use of the alt key.
When you push alt by itself it takes control to the menu.
Try pushing alt, releasing it, and then pushing the space bar (in just about
any program).
I haven't tried but I imagine you can probably stop the alt key from doing
this if you need to consecutively catch it - but if you are using menus in
your program it is likely that this will annoy a user who wishes to use the
menu in this fashion.
--
LTP
:)
Knute Johnson - 02 Jun 2006 17:22 GMT
>> Is this normal behaviour for the Alt key or is it a potential bug of the
>> JVM or OS???
[quoted text clipped - 15 lines]
>
> :)
What does Alt then Spacebar do on your computer? On mine it just dings.

Signature
Knute Johnson
email s/nospam/knute/
Luc The Perverse - 02 Jun 2006 21:08 GMT
>>> Is this normal behaviour for the Alt key or is it a potential bug of the
>>> JVM or OS???
[quoted text clipped - 17 lines]
>
> What does Alt then Spacebar do on your computer? On mine it just dings.
On a windows machine it should bring up the window control menu. It should
do this unless your foreground window doesn't have a title bar, or the menu
has been disabled.
--
LTP
:)
Knute Johnson - 03 Jun 2006 00:15 GMT
>>>> Is this normal behaviour for the Alt key or is it a potential bug of the
>>>> JVM or OS???
[quoted text clipped - 23 lines]
>
> :)
On Thunderbird, the newsreader that I use, ALT then Spacebar causes a
ding. On Pegasus, my email client it brings up the window menu with
Restore, Minimize, and Close.
In either case I'm not sure why when no other window or component takes
the focus that it should consume the keypressed event. Where are they
going if not to some menu? If you press the Windows menu key it
consumes both keypressed and keyreleased until it is gone.
Interestingly enough F10 operates similarly to ALT.

Signature
Knute Johnson
email s/nospam/knute/
Luc The Perverse - 03 Jun 2006 01:01 GMT
>>>> --
>>>> LTP
[quoted text clipped - 20 lines]
>
> Interestingly enough F10 operates similarly to ALT.
That is because F10 also brings up the menu ;)
It is not that Alt is not being pressed and released again, just that the
component that you are listening from is not getting the message because the
Alt key has given focus to the menu.
--
LTP
:)
Knute Johnson - 03 Jun 2006 06:09 GMT
> It is not that Alt is not being pressed and released again, just that the
> component that you are listening from is not getting the message because the
> Alt key has given focus to the menu.
I got that but what component or window is getting the focus if there
isn't a window or other component?

Signature
Knute Johnson
email s/nospam/knute/
Chris Uppal - 03 Jun 2006 13:14 GMT
> what component or window is getting the focus if there
> isn't a window or other component?
Very Zen...
;-)
-- chris
Knute Johnson - 03 Jun 2006 17:02 GMT
>> what component or window is getting the focus if there
>> isn't a window or other component?
[quoted text clipped - 4 lines]
>
> -- chris
That's just too funny Chris!

Signature
Knute Johnson
email s/nospam/knute/