aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes About java.awt.Robot Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "About java.awt.Robot" Watch "About java.awt.Robot" New topic
Author

About java.awt.Robot

Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi, everyone.

I find a strange case when I use the class Robot.

It doesn't press the book button when I enter "1245" in the ownerText and then press Enter key.

Any advice will be appreciated!
Ailsa Cape
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
does your button fire if you press B?

or does it fire when you press ALT-B?
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi,Michael

Thank you for your reply.
Yes, when I press ALT-B, the book button fires as expected. I think the bold code above is to mimic the action of pressing ALT-B in the keyboard, but it doesn't work this way. After I enter something in the ownerText and press the Enter key, nothing happens. Could you give me some idea of it?

Thanks in advance!
Ailsa Cape
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Yes, when I press ALT-B, the book button fires as expected.

your robot only presses B
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi, Michael

How to make the robot presses ALT-B instead of B?

Thanks in advance!
Ailsa Cape
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
experiment a little

you have
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);

what about trying
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_B);
robot.keyRelease(KeyEvent.VK_ALT);
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi, Michael

Thank you! It works. The book button's shortcut key is B in the keyboard when I use "book.setMnemonic(KeyEvent.VK_B)". I don't know why I should have to press ALT-B to fire the button?

Thanks in advance!
Ailsa Cape
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: About java.awt.Robot