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

Keypad key codes are not unique

XMLWordPrintable

    • beta
    • generic, x86
    • generic, windows_nt



      Name: krT82822 Date: 01/19/99


      A unique key code is not reported for the keypads ENTER, LF, RT, UP,
      DN, INS, DEL, HOME, END, PAGE UP, and PAGE DN keystrokes. The
      keycode is the same as reported for the matching keys. The
      keycode is also the same for the left and right shift, and the
      left and right ctrl key.(The ENTER is high priority to me.)

      I wrote a sample C++ program. Although the virtual key code
      was the same the scan code was different between the main enter
      key and the keypad enter key.

      Although I have only tested using Windows NT I am told it also
      occurs on a SUN box.

      To reproduce, implement the following KeyListener methods.


         /** Handle the key typed event from the text field. */
          public void keyTyped(KeyEvent e) {
              displayInfo(e, "KEY TYPED: ");
          }

          /** Handle the key pressed event from the text field. */
          public void keyPressed(KeyEvent e) {
             displayInfo(e, "KEY PRESSED: ");
          }

          /** Handle the key released event from the text field. */
          public void keyReleased(KeyEvent e) {
              displayInfo(e, "KEY RELEASED: ");
          }
          
          protected void displayInfo(KeyEvent e, String s){
              String charString, keyCodeString, modString, tmpString;

              char c = e.getKeyChar();
              int keyCode = e.getKeyCode();
              int modifiers = e.getModifiers();

              if (Character.isISOControl(c)) {
                  charString = "key character = (an unprintable control character)";
              } else {
                  charString = "key character = '" + c + "'";
              }

              keyCodeString = "key code = " + keyCode+
                              " ("+ KeyEvent.getKeyText(keyCode)+ ")";

              modString = "modifiers = " + modifiers;
              tmpString = KeyEvent.getKeyModifiersText(modifiers);
              if (tmpString.length() > 0) {
                  modString += " (" + tmpString + ")";
              } else {
                  modString += " (no modifiers)";
              }

              System.out.println(s+" "+ charString);
              System.out.println(" "+ keyCodeString);
              System.out.println(" "+ modString);
          }

      You will notice the output when pressing the normal enter key
      and the keypad enter key both produce the same output:

      KEY PRESSED: key character = (an unprintable control character)
          key code = 10 (Enter)
          modifiers = 0 (no modifiers)
      KEY TYPED: key character = (an unprintable control character)
          key code = 0 (Unknown keyCode: 0x0)
          modifiers = 0 (no modifiers)
      KEY RELEASED: key character = (an unprintable control character)
          key code = 10 (Enter)
          modifiers = 0 (no modifiers)
      (Review ID: 52427)
      ======================================================================

      Name: krT82822 Date: 12/03/99


      Not relevant

      We would like some way of differentiating between the Enter key on the numeric
      keypad and the standard Enter key on the main key board. At the moment
      both register as the same virtual key.
      (Review ID: 98605)
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: