拖放机器人类

Nyx*_*Nyx 5 java awt awtrobot

我想使用 Java 中的 Robot 类进行拖放。由于某种原因,下面的代码不起作用。这种方法有替代方法吗?

    public static void main (String args []){
    Robot robot = new Robot ();

    robot.mouseMove(350, 226);
    robot.keyPress(InputEvent.BUTTON1_MASK);
    robot.mouseMove(250, 350);
    robot.keyRelease(InputEvent.BUTTON1_MASK);
Run Code Online (Sandbox Code Playgroud)

}

DNA*_*DNA 2

您需要使用mousePress()and mouseRelease(),而不是keyPress()andkeyRelease()