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

ASCII control character for "Escape" Ctrl + [ is wrong for keyPressed event

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P4
    • None
    • 5.0
    • client-libs
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      Java version 1.5.0_06

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP service Pack 2

      A DESCRIPTION OF THE PROBLEM :
      The keyPressed handler does not report the correct keychar for the KeyEvent when the following key is pressed: Ctrl [

      The above combo represents the ASCII control code for Escape. The keyPressed handler for the " Ctrl [ " combo keys reports the KeyEvent.getChar() value as '[' instead of Escape (0x1b).

      Other Ascii control characters such as Ctrl h is reported correctly by the keyPressed handler. The KeyEvent.getChar() reports the char as backspace.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just press the Ctrl key and the [ key.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting the Escape char (ox1b) to be reported by the KeyEvent.getChar() method for keyPressed handler. However, the keyTyped handler reports the correct char for KeyEvent.
      ACTUAL -
      When I pressed the Ctrl [ combo keys, I see the char reported as ' [ ' instead of being Escape.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      import java.awt.*;
      import java.awt.event.*;
       
       
      public class KeyStrokePanel extends JFrame implements KeyListener{
         
          int times = 0;
          private JTextArea textArea;
          
          public KeyStrokePanel() {
           addKeyListener(this);
              buildGUI();
          }
       
          private void buildGUI(){
              JPanel mainPanel = (JPanel) getContentPane();
              mainPanel.setLayout(new BorderLayout());
              JLabel instructions = new JLabel("<html><ul><li>Press any keys.</li>"
                      + "<li>You should see the event information displayed in the panel.</li></html>");
              mainPanel.add(instructions, BorderLayout.NORTH);
              JPanel centerPanel = buildCenterPanel();
              mainPanel.add(centerPanel, BorderLayout.CENTER);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
          }
            
       
          private void clearText()
          {
           textArea.setText("");
          }
          
          private void addText(String evtMsg) {
              textArea.append(times+ " "+evtMsg + '\n');
       
              times +=1;
       
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I haven't found a work around yet, but supsect that I can use the keyTyped event. However, it would be better to be consistant and have the keyPressed handler report the " ctrl [ " combo correctly for the KeyEvent.getChar() method.

      Attachments

        Activity

          People

            yan Yuri Nesterenko
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: