Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About java.awt.Robot

 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does your button fire if you press B?

or does it fire when you press ALT-B?
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Yes, when I press ALT-B, the book button fires as expected.

your robot only presses B
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Michael

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

Thanks in advance!
Ailsa Cape
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic