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

Key events incorrect for keys mapping to VK_NONCONVERT, VK_CONVERT, VK_HIRAGANA

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6u12
    • client-libs

      FULL PRODUCT VERSION :
      Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Running with Japanese local set up, Japanese keyboard

      A DESCRIPTION OF THE PROBLEM :
      Key events for 3 special keys on Japanese keyboards do not contain the key code, but instead come back as undefined.

      These are the 3 keys in question:

      1. The key to the immediate left of the space bar. This is the Non-conversion key (specifies that the kana characters entered are not to be converted into kanji candidates).

      2. The key to the immediate right of the space bar. This is the conversion key (Used to convert kana to kanji. In the Microsoft IME, Conversion selects conversion candidates on highlighted input, and Shift + Conversion is used to display the previous candidate, or zenkouho (前侯補). The alt version of this key is also pronounced zenkouho (全侯補), which means "all candidates", shows all input candidates. ).

      3. The key 2 keys to the right of the space bar. This is the key to switch between Hiragana and Katakana.

        See also http://en.wikipedia.org/wiki/Language_input_keys

      I don't know whether or not this is a regression.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the test code included. It prints out the hex value for the key code, which should match the value defined in java.awt.KeyEvent.

      For instance, if I press S follwed by Ctrl+C, I get the following output in the test program. It matches the hex values specified for VK_S (0x53) and VK_C (0x43)

      Pressed: Code = 53 Char = s Mods = <none> Action = false
      ---------------
      Typed: Code = 0 Char = s Mods = <none> Action = false
      ---------------
        Released: Code = 53 Char = s Mods = <none> Action = false
      ---------------
      Pressed: Code = 11 Char = ¿ Mods = Ctrl Action = false
      ---------------
      Pressed: Code = 43 Char = Mods = Ctrl Action = false
      ---------------
      Typed: Code = 0 Char = Mods = Ctrl Action = false
      ---------------
        Released: Code = 43 Char = Mods = Ctrl Action = false
      ---------------
        Released: Code = 11 Char = ¿ Mods = <none> Action = false
      ---------------

      However, when the 3 keys above are pressed (in order from left to right), I get the following output. There are no key codes, and the key typed events are not present.

      --------------------------------
      Pressed: Code = 0 Char = ? Mods = <none> Action = false
      ---------------
        Released: Code = 0 Char = ? Mods = <none> Action = false
      ---------------
      Pressed: Code = 0 Char = ? Mods = <none> Action = false
      ---------------
        Released: Code = 0 Char = ? Mods = <none> Action = false
      ---------------
      Pressed: Code = 0 Char = ? Mods = <none> Action = false
      ---------------
        Released: Code = 0 Char = ? Mods = <none> Action = false
      ---------------


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect to get the hex values for VK_NONCONVERT, VK_CONVERT/VK_PREVIOUS_CANDIDATE (when shift key is pressed), and VK_HIRAGANA/VK_KATAKANA (when shift key is pressed)
      ACTUAL -
      VK_UNDEFINED is always returned, no keytyped event.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.text.*;
      import java.awt.BorderLayout;
      import java.awt.MenuShortcut;
      import java.awt.Dimension;
      import java.awt.Component;
      import java.awt.Point;
      import java.awt.event.*;
      import java.io.FileWriter;
      import java.io.File;
      import java.io.IOException;

      public class KeyTest extends JFrame implements MouseListener, KeyListener, WindowListener, ActionListener
      {
          private static String sSeparator = new String("\n---------------" + "\n");

          TestOutput fTestOut;
          TestInput fTestIn;

          java.awt.MenuBar mainMenuBar = new java.awt.MenuBar();
          java.awt.Menu menu1 = new java.awt.Menu();
          java.awt.MenuItem logMenuItem = new java.awt.MenuItem();
          java.awt.MenuItem exitMenuItem = new java.awt.MenuItem();
          java.awt.Menu menu2 = new java.awt.Menu();
          java.awt.MenuItem cutMenuItem = new java.awt.MenuItem();
          java.awt.MenuItem copyMenuItem = new java.awt.MenuItem();
          java.awt.MenuItem pasteMenuItem = new java.awt.MenuItem();
          java.awt.MenuItem clearOutputMenuItem = new java.awt.MenuItem();

          public KeyTest()
          {
              this.getContentPane().setLayout(new BorderLayout());
              setSize(605,605);
              setVisible(false);
              String javaVer = System.getProperty("java.specification.version");
              setTitle("Key Tester: java VM version " + javaVer);

              // Initialize menus
              menu1.setLabel("File");
              menu1.add(logMenuItem);
              menu1.add(exitMenuItem);

              // File menu
              logMenuItem.setLabel("Save As...");
              exitMenuItem.setLabel("Exit");

              // Edit menu
              cutMenuItem.setEnabled(false);
              cutMenuItem.setLabel("Cut");
              cutMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_X,false));
              copyMenuItem.setEnabled(false);
              copyMenuItem.setLabel("Copy");
              copyMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_C,false));
              pasteMenuItem.setEnabled(false);
              pasteMenuItem.setLabel("Paste");
              pasteMenuItem.setShortcut(new MenuShortcut(java.awt.event.KeyEvent.VK_V,false));
              clearOutputMenuItem.setEnabled(true);
              clearOutputMenuItem.setLabel("Clear window contents");

              menu2.setLabel("Edit");
              menu2.add(cutMenuItem);
              menu2.add(copyMenuItem);
              menu2.add(pasteMenuItem);
              menu2.add(clearOutputMenuItem);

              mainMenuBar.add(menu1);
              mainMenuBar.add(menu2);
              setMenuBar(mainMenuBar);

              exitMenuItem.addActionListener(this);
              logMenuItem.addActionListener(this);
              clearOutputMenuItem.addActionListener(this);

              fTestOut = new TestOutput();
              fTestOut.setEditable(false);

              fTestIn = new TestInput();

              this.getContentPane().add(fTestIn.getDisplay(), BorderLayout.NORTH);
              this.getContentPane().add(fTestOut.getDisplay(), BorderLayout.CENTER);

              fTestIn.addKeyListener(this);
              this.addWindowListener(this);
              fTestOut.addMouseListener(this);
          }

          // KeyListener methods
          public void keyPressed(KeyEvent event)
          {
              fTestOut.append("Pressed: " + getKeyInfo(event));
              fTestOut.append(sSeparator);

          }
          public void keyReleased(KeyEvent event)
          {
              fTestOut.append("Released: " + getKeyInfo(event));
              fTestOut.append(sSeparator);
          }

          public void keyTyped(KeyEvent event)
          {
              fTestOut.append("Typed: " + getKeyInfo(event));
              fTestOut.append(sSeparator);
          }

          private String getKeyInfo(KeyEvent event)
          {
              String keycode = " Code = " + Integer.toHexString(event.getKeyCode());
              String keychar = " Char = " + event.getKeyChar();
              String keytext = " Text = " + KeyEvent.getKeyText(event.getKeyCode());
              String mods = KeyEvent.getKeyModifiersText(event.getModifiers());
              if (mods.length() == 0) {
                  mods = "<none> ";
              }
              String keyModifiers = " Mods = " + mods;
              boolean isAction = event.isActionKey();
              String actionvar = isAction ? "true" : "false";
              String keyIsAction = " Action = " + actionvar;

              return keycode + keychar + keyModifiers + keyIsAction;
          }

          // MouseListener methods
          public void mouseClicked(MouseEvent event)
          {
              fTestIn.requestFocus();
          }
          public void mouseEntered(MouseEvent event)
          {
          }
          public void mouseExited(MouseEvent event)
          {
          }
          public void mousePressed(MouseEvent event)
          {
          }
          public void mouseReleased(MouseEvent event)
          {
          }

          // WindowListener methods
          public void windowClosing(WindowEvent event)
          {
              KeyTest.this.setVisible(false); // Hide the invoking frame
              KeyTest.this.dispose(); // Free system resources
          }
          public void windowOpened(WindowEvent event)
          {
          }
          public void windowClosed(WindowEvent event)
          {
          }
          public void windowActivated(WindowEvent event)
          {
          }
          public void windowDeactivated(WindowEvent event)
          {
          }
          public void windowIconified(WindowEvent event)
          {
          }
          public void windowDeiconified(WindowEvent event)
          {
          }

          // ActionListener method
          public void actionPerformed(java.awt.event.ActionEvent event)
          {
              Object object = event.getSource();
              if (object == exitMenuItem) {
                  System.exit(0); // close the application
              }
              else if (object == clearOutputMenuItem) {
                  fTestOut.setText("");
                  fTestIn.setText("");
              }
              else if (object == logMenuItem) {
                  logInfo();
              }
          }

          private void logInfo()
          {
              FileWriter writer = null;
              File file = null;

              //TODO: put up dialog and get filename
              String fileName = "c:\\temp\\alblog.txt";
              JFileChooser chooser = new JFileChooser();
              chooser.setDialogTitle("Create Log File");
              int returnVal = chooser.showSaveDialog(fTestIn);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                  file = chooser.getSelectedFile();

                  if (file.isDirectory()) {
                      //TODO dialog
                      JOptionPane.showConfirmDialog(fTestIn, "You cannot select a directory. Please select a file",
                              "Directory", JOptionPane.OK_OPTION);
                      return;
                  }
                  if (file.isFile()) {
                      int overwrite = JOptionPane.showConfirmDialog(fTestIn, "File already exists; overwrite it?",
                      "FileExists", JOptionPane.YES_NO_OPTION);
                      if (overwrite != JOptionPane.YES_OPTION) {
                          return;
                      }

                  }

                  //fileName = chooser.getSelectedFile().getName();
                  //file = new File(fileName);
                  try {
                      writer = new FileWriter(file);
      String javaVer = System.getProperty("java.specification.version");
               writer.write("Key Tester: java VM version " + javaVer + "\n");

                      writer.write(fTestIn.getText());
                      writer.write("\n--------------------------------\n");
                      writer.write(fTestOut.getText());
                  }
                  catch (IOException e) {
                  }
                  finally {
                      if (writer != null) {
                          try {
                              writer.close();
                          }
                          catch (IOException ex) {}
                      }
                  }
              }
          }

          private class TestInput extends JTextArea
          {
              JScrollPane fScrollpane;
              TestInput()
              {
                  super(10, 20);
                  fScrollpane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              }

              JScrollPane getDisplay()
              {
                  return fScrollpane;
              }
          }

          private class TestOutput extends JTextArea
          {
              JScrollPane fScrollpane;
              TestOutput()
              {
                  super(10,20);
                  fScrollpane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
              }

              JScrollPane getDisplay()
              {
                  return fScrollpane;
              }
          }


          static public void main(String args[])
          {
              try
              {
                  // Set to windows look-and-feel
                  String x = UIManager.getSystemLookAndFeelClassName();
                  if (x != null) {
                      try {
                          UIManager.setLookAndFeel(x);
                      }
                      catch (Exception e) {}
                  }

                  //Create a new instance of our application's frame, and make it visible.
                  (new KeyTest()).setVisible(true);
              }
              catch (Throwable t)
              {
                  System.err.println(t);
                  t.printStackTrace();
                  //Ensure the application exits with an error condition.
                  System.exit(1);
              }
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: