United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4840172 : Need some more explanation about KeyEvent.getKeyChar()

Details
Type:
Bug
Submit Date:
2003-03-31
Status:
Resolved
Updated Date:
2003-05-25
Project Name:
JDK
Resolved Date:
2003-05-25
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P5
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

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


                                     
2004-06-14
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
                                     
2003-04-06
EVALUATION

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



Hardware and Software, Engineered to Work Together