Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.awt.Robot and java.awt.event.KeyEvent.VK_COLON --- please help!

807603Aug 13 2004 — edited Dec 10 2007
Guys,

I'm writing a little swing app to ease some of my typing chores on my PC. I want to be able to use the Robot interface to automatically type sentences on the screen using KeyEvents. This works perfectly, to the wonder and amazement of my friends and family!

One snag: I can't get it to type a colon.

When I execute the code:
robot.keyPress(java.awt.event.KeyEvent.VK_SHIFT);         
robot.keyPress(java.awt.event.KeyEvent.VK_COLON);        
robot.delay(10);        
robot.keyRelease(java.awt.event.KeyEvent.VK_COLON);        
robot.delay(10);            
robot.keyRelease(java.awt.event.KeyEvent.VK_SHIFT);        
robot.delay(10);
I get the following error:
java.lang.IllegalArgumentException: Invalid key code        
at sun.awt.windows.WRobotPeer.keyPress(Native Method)        
at java.awt.Robot.keyPress(Robot.java:222)
I can't figure out why VK_COLON is coming up invalid. It should be a valid KeyEvent. According to all the docs (http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html) it's a valid constant.

What do I do next?

Thanks!
chewy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2008
Added on Aug 13 2004
5 comments
1,061 views