Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

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!!
0
nur_ismail
Asked:
nur_ismail
1 Solution
 
OviCommented:
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();
          }
     }
}
0
 
nur_ismailAuthor Commented:
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!!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
nur_ismailAuthor Commented:
what i really need is a method to post events on the AWT queue!
0
 
CEHJCommented:
Try getting the event queue

EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();
 

and then calling q.postEvent(x)
0
 
CleanupPingCommented:
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.
0
 
girionisCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now