Skip to Main Content

Java SE (Java Platform, Standard Edition)

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 on windows

843807Dec 8 2008 — edited Jan 27 2009
Hello,

I'm having problems with the Robot class when trying to simulate SHIFT+ARROW_LEFT (or any other cursor key) on windows. Things are working fine on linux when I run this code:

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_SHIFT);

The character left to the cursor gets selected. But this code doesn't work on windows. The cursor is moved one character to the left, but nothing is selected. I made a keyboard event listener and according to it it looks like if the SHIFT key is released before the arrow key is pressed. Here is the output of the event listener.

DOWN keyCode:131072 stateMask:0
UP keyCode:131072 stateMask:131072
DOWN keyCode:16777220 stateMask:0
UP keyCode:16777220 stateMask:0
DOWN keyCode:131072 stateMask:0
UP keyCode:131072 stateMask:131072

Could someone please explain what is happening? Why is windows releasing the SHIFT key before pressing the VK_RIGHT? On linux this is not happening.
In case you are wondering... I ma making some macros for the IDE.

Thanks
Toba
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 24 2009
Added on Dec 8 2008
4 comments
367 views