如何移动光标并单击 java 屏幕中的特定像素

How to move cursor and click on a specific pixel in java screen

我正在尝试将光标移动到屏幕中的特定像素并使用 java 程序单击它。

我尝试截取屏幕截图然后对其进行处理,但我卡住了。

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle)

您可以在java中使用Robotclass用鼠标点击特定像素 并使用 move 方法移动它。

import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.InputEvent;

public class MouseClicker {

    static Robot rb;

    public static void main(String[] args) {
        try {
            rb = new Robot();
        } catch (AWTException e) {
            System.out.println("Error while creating object" + e);
        }
        rb.mouseMove(1360, 768); //this method takes two parameters (Height, Width)
        rb.mousePress(InputEvent.BUTTON1_DOWN_MASK);//this method takes one parameter (BUTTON) to press it
        rb.delay(10); //this is the delay between every press
        rb.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);//this method takes one parameter (BUTTON) to release it
    }
}

有关更多参考,您可以查看 Oracle Docs