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

Robot.keyPress(KeyEvent.VK_RIGHT) always types Numpad right arrow key

    XMLWordPrintable

Details

    • Cause Known
    • x86
    • windows_2000, windows_7

    Description

      On windows, Robot.keyPress(KeyEvent.VK_RIGHT) always types NumPad right arrow key regardless of the NumLock on or off. There is no way to force the Robot to to press the non-numpad arrow key.

      Tested with jdk 1.4.2 b18.

      Steps to reproduce:

      1. Compile altkey.java attached below.
      2. run using 'java altkey auto'
      3. Robot always presses numpad right arrow key.
      4. Some character is typed in the textfield.

      5. run using 'java altkey man'
      6. Press Alt+Right (non-numpad key) and release in the textfield.
      7. No character will be typed in the testfield.



      ///////////////////////////////////////////////////////////
      import java.awt.*;
      import java.awt.event.*;

      public class altkey
      {
      Frame frame;
      TextField tf;
      TextArea ta;
      Robot robot;
      int keycode;

      public static void main(String argv[]){
      new altkey(argv[0]);
      }

      public altkey(String string){
      Frame frame = new Frame("Alt+Right Test");
      frame.setLayout(new FlowLayout());
      tf = new TextField("TextField");
      frame.add(tf);

      frame.pack();
             frame.setVisible(true);
             tf.addKeyListener(new KeyAdapter(){
      public void keyPressed(KeyEvent e) {
      keycode = e.getKeyCode();
      System.out.println("TF key pressed:" + e.getKeyCode());
      System.out.println("KeyLocation: " + e.getKeyLocation());
      }
      public void keyReleased(KeyEvent e) {
      keycode = e.getKeyCode();
      System.out.println("TF key released:" + e.getKeyCode());
      }
      });
      try {
      robot = new Robot();
      } catch (AWTException e) {
      System.out.println("Problem creating Robot. FAIL.");
      throw new RuntimeException("Problem creating Robot. FAIL.");

             }
      robot.setAutoDelay(1000);
      if(string.equals("auto")) {
      auto();
      robot.setAutoDelay(3000);
      frame.dispose();
      }

      }

      public void auto() {
      //Click on the TextField
      int textX = (tf.getLocationOnScreen()).x;
      int textY = (tf.getLocationOnScreen()).y;
      robot.mouseMove( textX+2, textY+2);
      robot.mousePress(InputEvent.BUTTON1_MASK);
      robot.delay(100);
      robot.mouseRelease(InputEvent.BUTTON1_MASK);
      tf.setText("");

      robot.keyPress(KeyEvent.VK_ALT);
      robot.setAutoDelay(200);
      robot.keyPress(KeyEvent.VK_RIGHT);
      robot.keyRelease(KeyEvent.VK_RIGHT);

      robot.setAutoDelay(200);
      robot.keyRelease(KeyEvent.VK_ALT);
      robot.setAutoDelay(200);
      if(tf.getText() != null) {
      System.out.println("Fail: Some Symbol is typed when pressed Alt+Right arrow keys pressed");
      }
      else {
      System.out.println("Pass");
      }
      }
      }

      ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

      Attachments

        Issue Links

          Activity

            People

              dav Andrei Dmitriev (Inactive)
              asamjisunw Aruna Samji (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: