Name: jl125535 Date: 03/27/2003
FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
FULL OS VERSION :
Linux galahad 2.4.20 #2 Mon Dec 16 22:53:44 CET 2002 i686 unknown
A DESCRIPTION OF THE PROBLEM :
When adding a KeyListener to any kind of component, keyReleased events are fired when the key on the keyboard is held down.
This is different in windows. When holding a keyboard button down, keyPressed and keyTyped are fired, but keyReleased is only fired when releasing the button (behaviour as wished).
1.4.2 on Solaris 8 also exhibits the desired behavior.
Thus, on Linux it is difficult to write suitable keyListeners for instance for games, since you can never react approriate when you do not know if a key is held or not. A solution using a mechanism that will use timestamps in order to check every n milliseconds whether an event has been fired or not is way to poor to implement, sorry.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the code below and press a key
EXPECTED VERSUS ACTUAL BEHAVIOR :
keyReleased should only be fired when the key is actually released.
keyReleased is fired when the key is held down
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test
* @param args the command line arguments
public static void main(String args)
JFrame fr = new JFrame();
JLabel l = new JLabel("a label");
l.addKeyListener(new KL() );
private static class KL implements KeyListener
public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e)
public void keyTyped(KeyEvent e)
---------- END SOURCE ----------
(Review ID: 182446)