JDK-4676732 : REGRESSION: Robot.keyPress() throws IllegalArgumentException in Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-04-29
  • Updated: 2002-10-18
  • Resolved: 2002-10-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Description

Name: jk109818			Date: 04/29/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Service Pack 2

EXTRA RELEVANT SYSTEM CONFIGURATION :
Standard US Keyboard

A DESCRIPTION OF THE PROBLEM :
I have an application that records KeyEvents from a
KeyListener to play the keystrokes back with Robot.  This
seems to work in Linux, but in Windows I get an
IllegalArgumentException for some keys.

My attached source code will reproduce the error by waiting
5 seconds for you to switch to your favorite text editor,
then after 5 seconds it presses the keys "y.z"

Running in Linux I see the "y.z" keys typed into the text
editor.  In Windows I see the "y" key typed then the
exception is thrown.

For my test I am running on a dual boot system that boots
both Linux and Windows.  Both operating systems are running
JDK 1.4.  Although I have not thoroughly tested every
possible key I have noticed that a number of keys do not
work in Windows, including ".\;:"


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run sample code
2. Switch to Notepad
3. Robot attempts to send "y.z" keys to notepad, throws
exception on the "." key.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect to see the keys "y.z" typed into the notepad
window, I only get "y", then an exception.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: Invalid key code
        at sun.awt.windows.WRobotPeer.keyPress(Native Method)
        at java.awt.Robot.keyPress(Robot.java:222)
        at TestRobot.main(TestRobot.java:14)

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;

public class TestRobot {
    public static void main(String args[]) {
        try{
            Robot robot = new Robot();

            System.out.println("sending keys in 5 seconds...");
            Thread.currentThread().sleep(5000);
            
            robot.keyPress(KeyEvent.VK_Y);
            robot.keyRelease(KeyEvent.VK_Y);
            robot.keyPress(KeyEvent.VK_PERIOD);
            robot.keyRelease(KeyEvent.VK_PERIOD);
            robot.keyPress(KeyEvent.VK_Z);
            robot.keyRelease(KeyEvent.VK_Z);
            
            System.out.println("DONE sending keys.");
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Use Linux instead of Windows.

Release Regression From : 1.3.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 145901) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b04
14-06-2004

EVALUATION Important functionality not working - could impact testing. ###@###.### 2002-04-29 I wonder if this is caused by the way we iterate through the dynamically mapped keys on Windows on a robot keypress? dynamicKeyMapTable[] has java_awt_event_KeyEvent_VK_UNDEFINED for the jkey in each entry. ###@###.### 2002-04-29
29-04-2002