Link to home
Start Free TrialLog in
Avatar of nur_ismail
nur_ismail

asked on

Fake Mouse Event Generation

hello,
i would like to write a program in JAVA that generates mouse events.. for example
it should move the cursor or click on an icon... all this automatically!!
can you write a simple example or tell me wich class to use?
thanks very much!!
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Ovi
Ovi

package tests.awt;

import java.awt.AWTException;
import java.awt.Robot;

/**
 * @author ovi
 */
public class RobotDemo {

     public static void main(String[] args) {
          try {
               Robot robot = new Robot();
               int i = 0;
               while(i < 50) {
                    int x = (int) Math.round(Math.random() * 1000);
                    int y = (int) Math.round(Math.random() * 1000);
                    robot.mouseMove(x, y);
                    robot.delay(500);
                    i++;
               }
          } catch (AWTException e) {
               e.printStackTrace();
          }
     }
}
Avatar of nur_ismail

ASKER

thanks a lot..
but with the class robot i can't generate the mouse click
or the double click on any point of the screen!!
what i really need is a method to post events on the AWT queue!
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nur_ismail:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer