BUG: KEY_PRESSED Event Not Generated for Some Controls

SYMPTOMS

Programs that try to respond to KEY_PRESSED events miss those events for
certain keys and certain controls that use the 1.1 or 1.02 eventing model
of the Java Development Kit (JDK) from Sun Microsystems Inc. For example,
this problem occurs when trying to intercept a TAB inside a TextArea.

CAUSE

Certain controls do not generate KEY_PRESSED or ACTION_PRESSED events, or
call the keyPressed method of a KeyListener, for certain keys.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a Java project and include the following class:
    import java.awt.*;// To see JDK 1.1-style events, uncomment this line.// import java.awt.event.*;public class Testevent{   public static void main(String args[])   {      Frame f=new Frame();      f.setLayout(new java.awt.BorderLayout());      TextArea ta = new TextAreaEvents();      f.add("Center", ta);      f.setSize(320,200);      f.setVisible(true);      // To see JDK 1.1-style events, uncomment this line.      // To see JDK 1.02-style events, leave it out.      // ta.addKeyListener(new TestKeyListener());   }}class TextAreaEvents extends TextArea{   public boolean handleEvent(Event e)   {      System.out.println(e);      System.out.print(e.id==Event.KEY_PRESS? "KEY_PRESS":"");      System.out.print(e.id==Event.KEY_RELEASE? "KEY_RELEASE":"");      System.out.print(e.id==Event.KEY_ACTION? "KEY_ACTION":"");      System.out.print(e.id==Event.KEY_ACTION_RELEASE?                       "KEY_ACTION_RELEASE":"");      System.out.println();      return super.handleEvent(e);   }}// To see JDK 1.1-style events uncomment the following class:/*class TestKeyListener implements KeyListener{   public void keyPressed(KeyEvent e)   {     System.out.println("Listener -- pressed: "+e);   }   public void keyTyped(KeyEvent e)   {      System.out.println("Listener -- typed: "+e);   }   public void keyReleased(KeyEvent e)   {      System.out.println("Listener -- released: "+e);   }}/* End of block. */ 
  2. Build and execute the above Java class. You will notice that the
    TextArea control does not generate KEY-PRESSED events for the TAB key.

Other Affected Keys

You will notice that the following controls do not create KEY_PRESSED or
ACTION_PRESSED events, or call keyPressed(), for the following keys:


Button SPACE, ENTER
Choice SPACE, ENTER, HOME, END, PGUP, PGDOWN, ARROWUP, ARROWLEFT, ARROWRIGHT, ARROWDOWN
Checkbox SPACE, ENTER
List SPACE, ENTER, HOME, END, PGUP, PGDOWN, ARROWUP, ARROWLEFT, ARROWRIGHT, ARROWDOWN
TextArea TAB, PGUP, PGDOWN

Propiedades

Id. de artículo: 188808 - Última revisión: 02/14/2017 - Revisión: 1

Microsoft Virtual Machine for Java, Microsoft Software Development Kit for Java 2.02, Microsoft Software Development Kit for Java 2.02, Microsoft Software Development Kit for Java 2.01, Microsoft Software Development Kit for Java 2.02, Microsoft Software Development Kit for Java 2.02, Microsoft Software Development Kit for Java 3.0, Microsoft Software Development Kit for Java 3.1, Microsoft Software Development Kit for Java 3.2, Microsoft Visual J++ 1.0 Standard Edition, Microsoft Visual J++ 1.1 Standard Edition

Comentarios