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

KeyEvent.getKeyCode() not consistent across platforms

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.4.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: bsC130419 Date: 07/10/2001


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


      The problem encountered is a discrepency between the KeyEvent.getKeyCode()
      return value for KeyPressed events. On one system, Linux Redhat7.1, pressing the
      SHIFT and +/= button results in a VK_SHIFT followed by a VK_PLUS. This is what I
      believe to be the correct behavior. On the second system, Windows 2000, the same
      combination of keystrokes results in a VK_SHIFT followed by a VK_EQUALS.

      Try this code to demonstrate :

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


      public class KeyTest extends JTextField{

        public KeyTest() {
          setPreferredSize(new java.awt.Dimension(200,200));
          addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
              divulgeError(e);
            }
          });
          requestFocus();
        }

        public void divulgeError(KeyEvent e) {
          Class k = java.awt.event.KeyEvent.class;
          java.lang.reflect.Field[] f = k.getDeclaredFields();
          for (int i = 0; i < f.length; i++) {
            try {
            if (f[i].getName().indexOf("VK_") < 0) continue;
            if (f[i].getInt(null) == e.getKeyCode())
              System.out.println(f[i].getName());
            } catch (Exception ex) {ex.printStackTrace();}
          }
        }

        public static void main(String[] args) {
          KeyTest test = new KeyTest();
          JFrame frame = new JFrame();
          frame.getContentPane().add(test);
          frame.pack();
          frame.setVisible(true);
        }
      }
      (Review ID: 127779)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              ehawkessunw Eric Hawkes (Inactive)
              Reporter:
              bstrathesunw Bill Strathearn (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: