Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4676732
Votes 9
Synopsis REGRESSION: Robot.keyPress() throws IllegalArgumentException in Windows
Category java:classes_awt
Reported Against 1.4
Release Fixed 1.4.2(mantis)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 29-APR-2002
Description




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) 
======================================================================
Work Around
N/A
Evaluation
Important functionality not working - could impact testing.  
 xxxxx@xxxxx  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.  

 xxxxx@xxxxx  2002-04-29
Comments
  
  Include a link with my name & email   

Submitted On 03-MAY-2002
wnasuti
I have observed the same behaviour on Windows (NT4.0) with 
the VK_COLON, VK_SEMICOLON, and VK_BACK_SLASH under build 
1.4.0-b92. A work around would be great to allow regression 
testing.


Submitted On 03-MAY-2002
wnasuti
I'm not sure how valuable this data point is, but I did 
verify that this bug does not exist on Windows (NT4.0) 
using build 1.3.1._03-b03


Submitted On 20-JUN-2002
nathanj
Upgrading to DirectX 8.1 seems to make this problem go away.


Submitted On 15-JUL-2002
hotbee
Yes, I had the problem too when I developed a proof-of-
concept Ad-hoc Remote Control program in April 2002, it 
worked with Win2k perfectly even with swedish/chinese 
keyboard layout on JDK v1.3. But after migrated to JDK 
v1.4, some keystrokes (especially punctuation keys)could 
not be reproduced correctly. It is a pity that this bug 
seems hasn't been fixed in the latest 1.4.1 beta version.


Submitted On 08-JAN-2005
al94
I have the same problem in XP with jdk 1.4.2, jdk1.5.
All the punctuation.



PLEASE NOTE: JDK6 is formerly known as Project Mustang