views:

67

answers:

1

I want to quickly click on another application when some event occurs in my Java application.

Given that I know the coordinates on the screen where I want to register a click, is it possible for my Java app to tell the OS to click there?

I will probably want to register multiple clicks.

I may also/instead want to register keyboard strokes. Is this possible also?

+6  A: 

You should take a look at the Robot class in Java. It will allow you to simulate clicks and mouse movement.

The methods in particular that you probably want are:

void    keyPress(int keycode) 
          Presses a given key.
void    keyRelease(int keycode) 
          Releases a given key.
void    mouseMove(int x, int y) 
          Moves mouse pointer to given screen coordinates.
void    mousePress(int buttons) 
          Presses one or more mouse buttons.
void    mouseRelease(int buttons) 
          Releases one or more mouse buttons.
jjnguy
Thanks. That's exactly what I needed. I appreciate it.
barryred
@barryred, Glad to help!
jjnguy