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

Lightweight component receives incorrect KeyEvents for accented keys

    • b40
    • generic, x86, sparc
    • linux, linux_sun, solaris_8

      Name: boT120536 Date: 08/10/2001


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

      I use Solaris 8, CDE Window Manager and Java SDK 2 v1.3.1. The keyboard is a
      Sun type 6 USB keyboard. The keyboard layout is modified through xmodmaprc as
      follows (to mime Hungarian keyboard layout in order to access hunarian accented
      characters via one key press (remapped pairs: a'-;, e'-', i'-`, o'-=, o:-0, o"-
      [, u'-], u:--, u"-\)):
      keycode 59= 0xe1 0xc1 0x27 0x22
      keycode 58= 0xe9 0xc9 0x3b 0x3a
      keycode 60= 0xed 0xcd 0x60 0x7e
      keycode 53= 0xf3 0xd3 0x3d 0x2b
      keycode 46= 0xf6 0xd6 0x30 0x29
      keycode 52= 0xfc 0xdc 0x2d 0x5f
      keycode 54= 0xf5 0xd5 0x5b 0x7b
      keycode 56= 0xfb 0xdb 0x5c 0x7c
      keycode 55= 0xfa 0xda 0x5d 0x7d
      keycode 125= 0xff1b 0xff1b 0xff1b 0xff1b
      keycode 48= 0xffca 0xffca 0xffca 0xffca
      keycode 102 = 0xffb7
      keycode 99 = 0xffb4
      keycode 100 = 0xffb5
      keycode 101 = 0xffb6
      keycode 94 = 0xffab
      keycode 92 = 0xffd7
      keycode 106 = 0xffff
      keycode 104= 0xffb9
      keycode 103= 0xffb8
      keycode 96= 0xffb1
      keycode 97= 0xffb2
      keycode 98= 0xffb3
      keycode 105= 0xffb0
      keycode 35= 0x7a 0x5a
      keycode 36= 0x79 0x59
      remove Lock = Caps_Lock
      remove Control = Control_L
      keysym Control_L = Caps_Lock
      keysym Caps_Lock = Control_L
      add Lock = Caps_Lock
      add Control = Control_L
      keycode 108 = NoSymbol

      Though there's no problem with AWT components and the accented characters,
      swing components does not receive KEY_PRESSED events for the 'accented' keys,
      the key code in the events is always zero, and the key char differs in
      KEY_RELEASED from that of KEY_TYPED in case of the super-ASCII unicode
      characters.

      The (somewhat edited) result of the test code is (P=pressed, T=typed,
      R=released. The format is EventTypeKeyCode-KeyChar-(int)KeyChar). Keys pressed
      are ;[=a in both cases
      AWT component
      P0-?-233 T0-?-233 R0-?-233
      P0-?-245 T0-?-245 R0-?-245
      P0-?-243 T0-?-243 R0-?-243
      P65-a-97 T0-a-97 R65-a-97

      Swing component
      T0-?-233 R0-?-233 # missing key pressed event
      T0-o-337 R0-?-245 # different (code page converted) key char in KEY_RELEASED
      T0-?-243 R0-?-243
      P65-a-97 T0-a-97 R65-a-97 # correct result for regular key

      Listening to AWT key events provides an even weirder result... UNcomment
      commented lines to experience it.

      The test code follows:

      import java.util.*;

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;


      public class TestFrame extends JFrame
      {
      public TestFrame()
      {
      addWindowListener(new ExitAdapter());

      TextField textField = new TextField();
      JTextField textField2 = new JTextField();

      getContentPane().add(textField, BorderLayout.NORTH);
      getContentPane().add(textField2, BorderLayout.SOUTH);

      KAdapter adapter = new KAdapter();
      textField2.addKeyListener(adapter);
      textField.addKeyListener(adapter);

      /*
      Toolkit.getDefaultToolkit().addAWTEventListener(adapter,
      AWTEvent.KEY_EVENT_MASK);
      */
      }



      public static void main(String[] args)
      {
      TestFrame frame = new TestFrame();

      frame.pack();
      frame.show();
      }


      class KAdapter extends java.awt.event.KeyAdapter implements
      java.awt.event.AWTEventListener
      {
      public void eventDispatched(AWTEvent event)
      {
      /*
      System.out.print(" AWT" + event.getID() + " ");
      */
      }

      public void keyTyped(java.awt.event.KeyEvent e)
      {
      key(e, 'T');
      }
      public void keyPressed(java.awt.event.KeyEvent e)
      {
      key(e, 'P');
      }
      public void keyReleased(java.awt.event.KeyEvent e)
      {
      key(e, 'R');
      }
      public void key(java.awt.event.KeyEvent e, char type)
      {
      int code = e.getKeyCode();
      char khar = e.getKeyChar();
      int charInt = (int) khar;
      System.out.print(type);
      System.out.print(code);
      System.out.print('-');
      System.out.print(khar);
      System.out.print('-');
      System.out.print(charInt);
      System.out.print(' ');
      if (type == 'R')
      System.out.println();
      }
      };
      }

      I have not experienced these problems on Windows 2000, Java SDK 1.3.1,
      Hungarian regional settings.

      Kertes Gabor
      (Review ID: 129071)
      ======================================================================

      Name: jk109818 Date: 12/20/2001


      FULL PRODUCT VERSION :
      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build
      1.4.0-rc-b87)
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b87, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      SunOS 5.8 Generic_108528-01 sun4u sparc SUNW,Ultra-5_10
      with French locale and French keyboard.


      A DESCRIPTION OF THE PROBLEM :
      KeyPressed Event is not called, when I pressed accented
      characters from the French keyboard.

      ? 00B2 Superscript two
      ? 00E0 Latin small letter a with grave
      ? 00E7 Latin small letter c with cedilla
      ? 00E8 Latin small letter e with grave
      ? 00E9 Latin small letter e with acute
      ? 00F9 Latin small letter u with grave


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the following program
      2. Key in the following list to jTextField1 from French
      keyboard
      //exp: the keycode is displayed as well as other keys.
      //act: nothing is displayed.

      ? 00B2 Superscript two
      ? 00E0 Latin small letter a with grave
      ? 00E7 Latin small letter c with cedilla
      ? 00E8 Latin small letter e with grave
      ? 00E9 Latin small letter e with acute
      ? 00F9 Latin small letter u with grave


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected:
      The appropriate keycode is displayed on the standard output,
      after I key in the accented characters from French keyboard
      as well as other key tops.
      Actual:
      //act: Following keys display nothing to the standard
      output.

      ? 00B2 Superscript two
      ? 00E0 Latin small letter a with grave
      ? 00E7 Latin small letter c with cedilla
      ? 00E8 Latin small letter e with grave
      ? 00E9 Latin small letter e with acute
      ? 00F9 Latin small letter u with grave


      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Frame1.java
      package frenchkeyboard;

      import java.awt.*;
      import javax.swing.*;
      import java.awt.event.*;

      public class Frame1 extends JFrame {
        JTextField jTextField1 = new JTextField();

        public Frame1() {
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }
        public static void main(String[] args) {
          Frame1 frame1 = new Frame1();
          frame1.setSize(new Dimension(400,300));
          frame1.setVisible(true);
        }
        private void jbInit() throws Exception {
          jTextField1.setText("jTextField1");
          jTextField1.addKeyListener(new
      java.awt.event.KeyAdapter() {
            public void keyPressed(KeyEvent e) {
              jTextField1_keyPressed(e);
            }
          });
          this.getContentPane().add(jTextField1,
      BorderLayout.CENTER);
        }

        void jTextField1_keyPressed(KeyEvent e) {
          System.out.println("keyPressedKeycode:"+
      e.getKeyCode());
          System.out.println("keyPressedKeychar:"+
      e.getKeyChar());
        }
      }

      // End of Frame1.java
      ---------- END SOURCE ----------
      (Review ID: 137590)
      ======================================================================
      ###@###.### 2004-07-29

            yan Yuri Nesterenko
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: