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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.awt.Robot atomic operation (KeyPress + KeyRelease)

927811Apr 1 2012
I want just to know, if I code as follow:-

robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);


Does it guaranteed that the program will simulate key "A", only once?
I mean, when I do not write

<code> robot.keyRelease(KeyEvent.VK_A) </code>

Then the usual output shows :- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa......... until I press any key, even after program exits.

But when I usually use both statements, this normally not happen. But something strange happens while working last night. I use the following:-

robot.keyPress(KeyEvent.CTRL_MASK) // one more question?- should I use CTRL_DOWN_MASK here, instead
robot.keyPress(KeyEvent.VK_A)

I want to simulate "*ctrl+a*". But instead of expected result (*select all*), I got the following output:-
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa........ (about 16-17 "a", and then it automatically stopped).

Same is the case with "*shift+a*".
The problem happened, when I was running this code in "netbeans environment".

The problem what I'm suspecting is probably due to OS multiprocessing/multithreading environment. Please suggest me to make these two statements atomic, something else to deal with this problem........

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 29 2012
Added on Apr 1 2012
0 comments
1,136 views