This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,899 Users
  • 2,269,649 Discussions
  • 7,916,821 Comments

Discussions

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

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........
This discussion has been closed.