2

I am using a third party java library which spawns new JFrame windows. How do I make java.awt.Robot to send clicks and keyboard inputs to that specific window when it appears? I would run it in a separate thread so that other activities could be performed on the main application while robot is sending inputs to the specific JFrame window.

Note, I don't have api access to the process which spawns this JFrame window.

Currently, when the that JFrame window is minimized or closed, the robot will continue sending inputs to whatever current JFrame window is visible.

2
  • how do you get hold of the spawned frame? Commented Dec 14, 2011 at 13:02
  • not sure what you mean? it is triggered by an event produced by the library itself during runtime. there's no api to access this event. Commented Dec 14, 2011 at 21:41

1 Answer 1

1

You get all the frames launched by your application:

Frame[] frames = JFrame.getFrames();
//find the frame your looking for and call click(frame)

Click on the center of a component

click(Component c){

//get center 
Dimension size = c.getSize();
Point center = new Point(size.width/2, size.height/2);

//you might want to check if the component is showing.

Robot.mouseMove(center.getX(), center.getY());
Robot.keyPress(KeyEvent.VK_A);

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.