Java Robot 實戰:自動評論腳本

Java Robot 實戰:自動評論腳本

評論的好處

給別人評論一次,給自己的積分加一分。好處就不用我多說了⑧。

源代碼

package com.company;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

public class Main {

    public static void main(String[] args) throws AWTException {
   // write your code here
        Robot commenter = new Robot();
        //鼠標準備
        commenter.delay(3000);
        //先來個100下
        for(int i=0;i<100;i++){
            commenter.mousePress(InputEvent.BUTTON1_MASK);
            commenter.mouseRelease(InputEvent.BUTTON1_MASK);
            commenter.delay(200);
            commenter.mousePress(InputEvent.BUTTON1_MASK);
            commenter.mouseRelease(InputEvent.BUTTON1_MASK);
            commenter.delay(2000);
            //開始輸入
            commenter.keyPress(KeyEvent.VK_CONTROL);
            commenter.keyPress(KeyEvent.VK_V);
            commenter.delay(100);
            commenter.keyRelease(KeyEvent.VK_V);
            commenter.keyRelease(KeyEvent.VK_CONTROL);
            commenter.delay(200);
            //commit comment
            Point p = MouseInfo.getPointerInfo().getLocation();
            commenter.mouseMove((int)p.getX(),(int)p.getY()+78);
            commenter.delay(200);
            commenter.mousePress(InputEvent.BUTTON1_MASK);
            commenter.mouseRelease(InputEvent.BUTTON1_MASK);
            p = MouseInfo.getPointerInfo().getLocation();
            commenter.mouseMove((int)p.getX(),(int)p.getY()-78);
            commenter.delay(1000);
        }
    }
}

使用方法

把要評論的內容複製到剪貼板上。
將鼠標放置到博客的評論按鈕上,運行腳本即可。
有時第一次評論網頁反應會遲鈍,此時先手動粘貼一次評論。
不同的顯示器分辨率不同,所以部分常數可能需要你自己調整。

測試

不妨就在這個博客下測試,你我都有積分。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章