參考:Java-隨機滑動鼠標和點擊_胡安民的博客-CSDN博客_java移動鼠標點擊
import java.awt.*;
public class MouseTest {
? ? private Dimension dim; //存儲屏幕尺寸
? ? private Robot robot;//自動化對象
? ? public MouseTest() {
? ? ? ? dim = Toolkit.getDefaultToolkit().getScreenSize();
? ? ? ? System.out.println("屏幕大小為:" + dim.getWidth() + " " + dim.getHeight());
? ? ? ? try {
? ? ? ? ? ? robot = new Robot();
? ? ? ? } catch (AWTException e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
? ? public void Move(int width, int heigh) { ? ?//鼠標移動函數(shù)
? ? ? ? System.out.println("enter Move()...");
? ? ? ? try {
? ? ? ? ? ? robot.delay(60000);
? ? ? ? ? ? Point mousepoint = MouseInfo.getPointerInfo().getLocation();
? ? ? ? ? ? System.out.println("移動前坐標:" + mousepoint.x + " " + mousepoint.y);
? ? ? ? ? ? width += mousepoint.x;
? ? ? ? ? ? heigh += mousepoint.y;
? ? ? ? ? ? robot.mouseMove(width, heigh);
? ? ? ? } catch (Exception e) {
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? ? ? System.out.println("移動后坐標:" + width + " " + heigh);
? ? ? ? //robot.mousePress(InputEvent.BUTTON1_MASK);//鼠標單擊
? ? }
? ? public static void main(String args[]) throws Exception {
? ? ? ? MouseTest mmc = new MouseTest();
? ? ? ? int min = 60;
? ? ? ? for (int i = 0; i < min; i++) {
? ? ? ? ? ? System.out.println("=======第" + i + "次移動=======");
? ? ? ? ? ? System.out.println("mouse control start:");
? ? ? ? ? ? mmc.Move(1, 1);//坐標為相對坐標
? ? ? ? ? ? System.out.println("mouse control stop.");
? ? ? ? }
? ? }文章來源:http://www.zghlxwxcb.cn/news/detail-630891.html
}文章來源地址http://www.zghlxwxcb.cn/news/detail-630891.html
到了這里,關(guān)于Java 后端實現(xiàn)鼠標滾動,點擊事件的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!