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!!
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!!
See http://java.sun.com/j2se/1.4/docs/api/java/awt/Robot.html#mouseMove(int, int)
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();
}
}
}
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();
}
}
}
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!!
but with the class robot i can't generate the mouse click
or the double click on any point of the screen!!
ASKER
what i really need is a method to post events on the AWT queue!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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