Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag/Drop Robot Class

Tags:

java

awt

awtrobot

I would like to drag and drop using the Robot class in Java. For some reason the code below isn't working. Is there an alternative to this method?

    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);

}

like image 704
Nyx Avatar asked Nov 04 '22 05:11

Nyx


1 Answers

You need to use mousePress() and mouseRelease(), not keyPress() and keyRelease()

like image 70
DNA Avatar answered Nov 07 '22 20:11

DNA