devxlogo

Using the Java Robot Class

Using the Java Robot Class

This tip demonstrates a user interaction (mouse move & mouse click) using native Robot methods.

Here’s the algorithm of the program:

1. Quickly to move the mouse cursor to the upper left corner.

2. Slowly to move the mouse cursor to the lower left corner and then to stop the cursor on the “Start” button (for a Windows9x/NT/2000-based system).

3. Press this button to show START-menu.

4. Press this button again to close START-menu.

 import java.awt.*;public class example{ Robot robot=null; void _init() {  try {   robot = new Robot(); }  catch (AWTException AEX) { } } void _move() {  robot.mouseMove(20,1);  //screen resolution y=750 {1024x768}, y=585 {800x600}, y=460 {640x480};  int y=750;  //Sets the number of milliseconds this Robot sleeps after generating an event.  robot.setAutoDelay(5);  //moves the mouse to "Start"  for (int i=1;i


You can define the screen resolution by using abstract class java.awt.Toolkit.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist