Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Does Robot handle mouse exactly like human being? Implement a drag action.

3027154Sep 8 2015 — edited Sep 8 2015

In page Page Flow, I want to drag the "Source" from left panel to right panel by java Robot. The following is the sample code.

public static void main(String[] args) throws AWTException{

        Point start = new Point(184, 124);

        Point end = new Point(386, 175);

        int buttonMasks = InputEvent.BUTTON1_DOWN_MASK;

        java.awt.Robot robot = new java.awt.Robot();

        robot.mouseMove(start.x, start.y);

        robot.delay(1000);

        robot.mousePress(buttonMasks);

        robot.delay(1000);

        robot.mouseMove(end.x, end.y);

        robot.delay(1000);

        robot.mouseRelease(buttonMasks);

        robot.delay(250);

    }

But I can only see the mouse cursor is moved to the right panel, not the "Source" component. After execution, if I move the mouse MANUALLY back to the left panel, I can see that mouse is dragging the "Source" component, it is very weird. I guess that there is something with the javascript code on that page, the way it handles mouse event.

After robot makes a mousePress at line 08, if I make a long delay at line 09, for example robot.delay(5000);, and I move the mouse MANUALLY to the right panel, the "Source" component can be moved!

Anybody knows the reason?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2015
Added on Sep 8 2015
0 comments
1,476 views