JDK-4087389 : KeyEvents being mishandled.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.5
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-10-20
  • Updated: 1998-02-26
  • Resolved: 1998-02-26
Related Reports
Duplicate :  
Description

Name: rm29839			Date: 10/20/97


Problem:
KeyEvents are handled differently between Win95 and 
Solaris with TextFields.  Specifically, in the code provided, on 
Win95, consume() works correctly (i.e., on an 
InputEvent, consume() marks the event so that 
default processing from a component does not occur)
It does not on Solaris.  
Try the source code below:

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

public class SBRTextField extends TextField {
  // INSTANCE VARIABLES
  private SBRKeyEventHandler keyHandler;
  
  // CONSTRUCTOR
  public SBRTextField(int cols) {
    super(cols);
    this.keyHandler = new SBRKeyEventHandler();
    enableEvents(AWTEvent.KEY_EVENT_MASK);
  }
  
  /** Process key events in a special way before sending it on
   * to all listeners, etc.
   */
  public void processEvent(AWTEvent e) {
    if (e.getID() == KeyEvent.KEY_TYPED) {
      KeyEvent ke = (KeyEvent) e;      
      keyHandler.keyTyped(ke);
      ke.consume();
    }
    super.processEvent(e);
  }
  
  // INNER CLASS
  class SBRKeyEventHandler extends KeyAdapter {
    /** Method handles KeyPressed, KeyReleased sequences.  It upper-cases
     * appropriately, and translates from keyboard to Display characters
     */
    public void keyTyped(KeyEvent ke) {
      char c = ke.getKeyChar();
      c = Character.toUpperCase(c);
      ke.setKeyChar(c);
    }
  }

  // DEBUGGING MAIN
  public static void main(String[] args) {
    Frame f = new Frame();
    f.add(new SBRTextField(15));
    f.pack();
    f.setVisible(true);
  }
}

MEANWHILE,
there appears to be a bug on Win95 that does not 
occur on Solaris.  Specifically, any InputEvents
with set methods are supposed to be COPIED before
being sent to individual listeners; however, if
you remove "ke.consume()" above, you will note
that on Solaris, the component behaves
correctly, i.e., typed characters do not appear
as upper case characters despite the keyTyped() 
method in the KeyEventHandler.  On Win95,however,
the characters ARE upper-cased.
======================================================================

Comments
EVALUATION Verified that on Solaris, with 1.1.7, consuming KEY_TYPED events will not prevent characters from showing up in text field.
11-06-2004

PUBLIC COMMENTS Duplicate of 4100317. Problem is when KEY_TYPED events are received (before or after key is actually typed). Behaviour differs between Windows and Solaris.
10-06-2004

WORK AROUND Name: rm29839 Date: 10/20/97 I have not found a work around for either of these. ====================================================================== For the first case, you can consume the KEY_PRESSED events as a workaround. robi.khan@eng 1998-02-18
18-02-1998