Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4391000

Press and then release multiple keys don't send a release event for the last key

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • x86
    • linux



      Name: yyT116575 Date: 11/20/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      Here is the source of the demo i use to demonstrate the problem :

      import java.awt.*;
      import java.awt.event.*;

      public class TestKey extends Frame {
        public TestKey() {
          super();
          setSize(200, 200);
          
          addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
              System.out.println("pressed " + e.getKeyText(e.getKeyCode()));
            }
            public void keyReleased(KeyEvent e) {
              System.out.println("released " + e.getKeyText(e.getKeyCode()));
            }
          });
        }
        
        public static void main(String[] s) {
          TestKey t = new TestKey();
          t.setVisible(true);
        }
      }

      Run the demo.
      If you press the "a" key, the demo will print :

      pressed A
      released A
      pressed A
      released A
      pressed A
      released A
      ...

      This is logic if we consider that all pressed event should have a corresponding
      release event.

      But if you press "a", then "z", then you release "z" and then "a", you have :

      pressed A
      released A
      pressed A
      released A
      pressed A
      pressed Z
      released Z
      pressed Z
      released Z

      There is no release event for the last "presses A" ! And there is no way in java
      to know when the "a" key is released...

      This problem occurs at least under Linux and Windows, and it is very paintfull
      for apps like game...
      (Review ID: 112547)
      ======================================================================

            mbronsonsunw Mike Bronson (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: