How to simulate a real mouse click using java?

前端 未结 6 1619
清酒与你
清酒与你 2020-11-27 14:44

I\'m attempting to perform a mouse click in Java, to click something in an external program. To do this, I\'m using java.awt.robot, and the following code:

6条回答
  •  情歌与酒
    2020-11-27 15:40

    You could create a simple AutoIt Script that does the job for you, compile it as an executable and perform a system call there.

    in au3 Script:

    ; how to use: MouseClick ( "button" [, x, y [, clicks = 1 [, speed = 10]]] )
    MouseClick ( "left" , $CmdLine[1], $CmdLine[1] )
    

    Now find aut2exe in your au3 Folder or find 'Compile Script to .exe' in your Start Menu and create an executable.

    in your Java class call:

    Runtime.getRuntime().exec(
        new String[]{
            "yourscript.exe", 
            String.valueOf(mypoint.x),
            String.valueOf(mypoint.y)}
    );
    

    AutoIt will behave as if it was a human and won't be detected as a machine.

    Find AutoIt here: https://www.autoitscript.com/

提交回复
热议问题