JDK-4840172 : Need some more explanation about KeyEvent.getKeyChar()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2003-03-31
  • Updated: 2017-05-16
  • Resolved: 2003-05-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description
Here is the current doc for KeyEvent.getKeyChar()

    /**
     * Returns the character associated with the key in this event.
     * For example, the key-typed event for shift + "a" returns the
     * value for "A".
     *
     * @return the Unicode character defined for this key event.
     *         If no valid Unicode character exists for this key event,
     *         keyChar is <code>CHAR_UNDEFINED</code>.
     */

Although the class docs for KeyEvent explain that the keyChar is for 
character input, and that character input is reported in KEY_TYPED events, 
users are sometimes confused about this.  We should explain that getKeyChar() 
should not be used for KeyReleased or KeyPressed methods.  

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b08
14-06-2004

SUGGESTED FIX echawkes@jano:/net/jano/export/disk26/awt/echawkes/jdk15-3/src/share/classes/java/awt/event( 101 )% sccs diffs -C KeyEvent.java ------- KeyEvent.java ------- *** /tmp/dR8ai8N Sun Apr 6 14:03:44 2003 --- KeyEvent.java Sun Apr 6 14:03:39 2003 *************** *** 956,967 **** /** * Returns the character associated with the key in this event. ! * For example, the key-typed event for shift + "a" returns the ! * value for "A". * * @return the Unicode character defined for this key event. * If no valid Unicode character exists for this key event, ! * keyChar is <code>CHAR_UNDEFINED</code>. */ public char getKeyChar() { return keyChar; --- 956,972 ---- /** * Returns the character associated with the key in this event. ! * For example, the <code>KEY_TYPED</code> event for shift + "a" ! * returns the value for "A". ! * <p> ! * <code>KEY_PRESSED</code> and <code>KEY_RELEASED</code> events ! * are not intended for reporting of character input. Therefore, ! * the values returned by this method are guaranteed to be ! * meaningful only for <code>KEY_TYPED</code> events. * * @return the Unicode character defined for this key event. * If no valid Unicode character exists for this key event, ! * <code>CHAR_UNDEFINED</code> is returned. */ public char getKeyChar() { return keyChar; ###@###.### 2003-04-06
06-04-2003

EVALUATION This came up most recently as bugid 4835748. ###@###.### 2003-03-31
31-03-2003