In this example we are automating the process of creating mouse event using the java.awt.Robot
class.
package org.kodejava.awt;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
public class MovingMouseDemo {
public static void main(String[] args) {
try {
Robot robot = new Robot();
// Move mouse cursor to 200, 500
robot.mouseMove(200, 500);
// Press the mouse button #1.
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
// Scroll the screen down for a mouse with a wheel support.
robot.mouseWheel(150);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024