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

Robot cannot type VK_KP_RIGHT on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs
    • Fix Understood
    • x86
    • windows_2000

      Calling Robot.keyPress(KeyEvent.VK_KP_RIGHT) on Windows 2000 results in the following:

      Exception occurred during event dispatching:
      java.lang.IllegalArgumentException: Invalid key code
              at sun.awt.windows.WRobotPeer.keyPress(Native Method)
              at java.awt.Robot.keyPress(Robot.java:183)
              at RobotArrow.actionPerformed(RobotArrow.java:50)
              at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
              at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
              at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
              at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
              at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
              at java.awt.Component.processMouseEvent(Component.java:3715)
              at java.awt.Component.processEvent(Component.java:3544)
              at java.awt.Container.processEvent(Container.java:1164)
              at java.awt.Component.dispatchEventImpl(Component.java:2593)
              at java.awt.Container.dispatchEventImpl(Container.java:1213)
              at java.awt.Component.dispatchEvent(Component.java:2497)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
              at java.awt.Container.dispatchEventImpl(Container.java:1200)
              at java.awt.Window.dispatchEventImpl(Window.java:914)
              at java.awt.Component.dispatchEvent(Component.java:2497)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
              at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java

      VK_KP_RIGHT represents "the numeric keypad right arrow key." PC keyboards have numeric keypad right arrow keys, so I don't think this should be an illegal argument. I'm guessing that the same happens w/ left, up, and down as well.

      This is reproducible using 1.3.1 as well.

      I used the following test case:

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

      public class RobotArrow extends JTextField implements ActionListener, KeyListener {

          static Robot robot;

          public RobotArrow() {super();}

          public static void main(String[] args) {
              try {
                  robot = new Robot();
                  robot.setAutoDelay(100);
                  JFrame jf = new JFrame("RobotArrow");
                  RobotArrow jtf = new RobotArrow();
                  jtf.addKeyListener(jtf);
                  JButton jb = new JButton("Type Alt-Arrow");
                  jb.addActionListener(jtf);
                  jb.addKeyListener(jtf);
                  Container c = jf.getContentPane();
                  c.setLayout(new GridLayout(2,1));
                  c.add(jtf);
                  c.add(jb);
                  jf.setBounds(100, 100, 200, 200);
                  jf.setVisible(true);

              } catch (AWTException e) {
                  System.out.println("Couldn't create Robot");
              }
          }

          public void actionPerformed(ActionEvent e) {
              requestFocus();

              System.out.println("Typing ALT-VK_KP_RIGHT");
              robot.keyPress(KeyEvent.VK_KP_RIGHT);
              robot.keyRelease(KeyEvent.VK_KP_RIGHT);
          }

          public void keyPressed(KeyEvent e) { System.out.println(e); }
          public void keyReleased(KeyEvent e) { System.out.println(e); }
          public void keyTyped(KeyEvent e) { System.out.println(e); }
      }

            denis Denis Fokin (Inactive)
            bchristi Brent Christian
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: