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

KeyEvent.getKeyChar() not providing correct value for KeyPad values

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.1.4
    • Fix Version/s: 1.1.5
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Build:
      1.1.4
    • Introduced In Version:
    • Resolved In Build:
      1.1.5
    • CPU:
      sparc
    • OS:
      solaris_2.5.1
    • Verification:
      Not verified

      Description

      Using the following java program, you will see that no value is returned
      for a method invocation of getKeyChar() when the KeyPad keys are used. Having
      NumLock on or off does not seem to make any difference (although it should).


      import java.applet.*;
      import java.lang.*;
      import java.awt.*;
      import java.awt.event.*;

      public class Key extends Applet
      {
      private KeyWatch keyear;
      private Button but1;
      private Button but2;
      private TextArea fld;

      public Key() {}

      public void init()
      {
      keyear = new KeyWatch();

      this.setLayout(new FlowLayout(FlowLayout.CENTER, 30, 30));

      but1 = new Button("Press Me");
      but2 = new Button("Hit Me");
      fld = new TextArea("Some Text\nSome Text\nSome Text\nSome Text", 10, 20);

      this.add(but1);
      this.add(but2);
      this.add(fld);

      but1.addKeyListener(keyear);
      but2.addKeyListener(keyear);
      fld.addKeyListener(keyear);

      this.addKeyListener(keyear);
      }
      }

      class KeyWatch extends KeyAdapter
      {
      public void keyPressed(KeyEvent e)
      {
      System.out.print("KeyChar=" + e.getKeyChar());
      System.out.print(" KeyCode=" + e.getKeyCode() );
      System.out.println(" KeyText=" + e.getKeyText(e.getKeyCode()));
      }
      }

      // end of code

      So, with NumLock ON, as I press KeyPad keys 1-9 I get:
      KeyChar= KeyCode=35 KeyText=End
      KeyChar= KeyCode=40 KeyText=Down
      KeyChar= KeyCode=34 KeyText=Page Down
      KeyChar= KeyCode=37 KeyText=Left
      KeyChar= KeyCode=39 KeyText=Right
      KeyChar= KeyCode=36 KeyText=Home
      KeyChar= KeyCode=38 KeyText=Up
      KeyChar= KeyCode=33 KeyText=Page Up

      And, with NumLock OFF, I get:
      KeyChar= KeyCode=35 KeyText=End
      KeyChar= KeyCode=40 KeyText=Down
      KeyChar= KeyCode=34 KeyText=Page Down
      KeyChar= KeyCode=37 KeyText=Left
      KeyChar= KeyCode=39 KeyText=Right
      KeyChar= KeyCode=36 KeyText=Home
      KeyChar= KeyCode=38 KeyText=Up
      KeyChar= KeyCode=33 KeyText=Page Up

      I SHOULD GET:

      with NumLock ON
      KeyChar=1 KeyCode=97 KeyText=NumPad-1
      KeyChar=2 KeyCode=98 KeyText=NumPad-2
      KeyChar=3 KeyCode=99 KeyText=NumPad-3
      KeyChar=4 KeyCode=100 KeyText=NumPad-4
      KeyChar=5 KeyCode=101 KeyText=NumPad-5
      KeyChar=6 KeyCode=102 KeyText=NumPad-6
      KeyChar=7 KeyCode=103 KeyText=NumPad-7
      KeyChar=8 KeyCode=104 KeyText=NumPad-8
      KeyChar=9 KeyCode=105 KeyText=NumPad-9

      with NumLock OFF
      KeyChar= KeyCode=35 KeyText=End
      KeyChar= KeyCode=225 KeyText=Down
      KeyChar= KeyCode=34 KeyText=Page Down
      KeyChar= KeyCode=226 KeyText=Left
      KeyChar= KeyCode=227 KeyText=Right
      KeyChar= KeyCode=36 KeyText=Home
      KeyChar= KeyCode=224 KeyText=Up
      KeyChar= KeyCode=33 KeyText=Page Up

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dmcduffisunw Dale Mcduffie (Inactive)
              Reporter:
              dmcduffisunw Dale Mcduffie (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: