1. 程式人生 > >Java robot 機器人 自動編寫 holleword

Java robot 機器人 自動編寫 holleword

通過Java Robot API 實現自動編碼,注意把輸入法關掉,系統預設輸入法即可!

不多說了,直接上程式碼:

package robot;

import java.awt.Robot;
import java.awt.event.KeyEvent;

/**
 * Java 自動化生成代生成
 * @author Cloud
 * @data   2016-11-18
 * t
 */

public class RobotHelloWord {


public static void main(String[] args) throws Exception {
Robot bobot = new Robot();
robotHolleWord(bobot);
}

/**
* Java Robot 自動生成 helloWord
* @param bobot
*/
public static void robotHolleWord(Robot bobot){
bobot.keyPress(KeyEvent.VK_CONTROL);
bobot.keyPress(KeyEvent.VK_N);

bobot.keyRelease(KeyEvent.VK_CONTROL);
bobot.keyRelease(KeyEvent.VK_N);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_C);
bobot.keyRelease(KeyEvent.VK_C);
bobot.delay(500);


bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_H);

bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_E);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_E);
bobot.keyRelease(KeyEvent.VK_E);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_O);
bobot.keyRelease(KeyEvent.VK_O);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_W);

bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_W);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_O);
bobot.keyRelease(KeyEvent.VK_O);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_R);
bobot.keyRelease(KeyEvent.VK_R);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_D);
bobot.keyRelease(KeyEvent.VK_D);
bobot.delay(500);


bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_SLASH);
bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_8);

bobot.keyRelease(KeyEvent.VK_SLASH);
bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_8);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_8);

bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_8);
bobot.delay(300);


bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_T);
bobot.keyRelease(KeyEvent.VK_T);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_E);
bobot.keyRelease(KeyEvent.VK_E);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_S);
bobot.keyRelease(KeyEvent.VK_S);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_T);
bobot.keyRelease(KeyEvent.VK_T);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_DOWN);
bobot.keyRelease(KeyEvent.VK_DOWN);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(300);

bobot.keyPress(KeyEvent.VK_M);
bobot.keyRelease(KeyEvent.VK_M);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_A);
bobot.keyRelease(KeyEvent.VK_A);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_I);
bobot.keyRelease(KeyEvent.VK_I);
bobot.delay(200);


bobot.keyPress(KeyEvent.VK_N);
bobot.keyRelease(KeyEvent.VK_N);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ALT);
bobot.keyPress(KeyEvent.VK_SLASH);

bobot.keyRelease(KeyEvent.VK_ALT);
bobot.keyRelease(KeyEvent.VK_SLASH);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ENTER);
bobot.keyRelease(KeyEvent.VK_ENTER);
bobot.delay(500);

bobot.keyPress(KeyEvent.VK_S);
bobot.keyRelease(KeyEvent.VK_S);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_Y);
bobot.keyRelease(KeyEvent.VK_Y);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_S);
bobot.keyRelease(KeyEvent.VK_S);
bobot.delay(200);


bobot.keyPress(KeyEvent.VK_O);
bobot.keyRelease(KeyEvent.VK_O);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_ALT);
bobot.keyPress(KeyEvent.VK_SLASH);

bobot.keyRelease(KeyEvent.VK_ALT);
bobot.keyRelease(KeyEvent.VK_SLASH);
bobot.delay(200);

bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_QUOTE);
bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_QUOTE);

bobot.keyPress(KeyEvent.VK_CAPS_LOCK);
bobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
bobot.delay(500);
bobot.keyPress(KeyEvent.VK_H);
bobot.keyRelease(KeyEvent.VK_H);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_CAPS_LOCK);
bobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_E);
bobot.keyRelease(KeyEvent.VK_E);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_O);
bobot.keyRelease(KeyEvent.VK_O);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_CAPS_LOCK);
bobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_W);
bobot.keyRelease(KeyEvent.VK_W);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_CAPS_LOCK);
bobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_O);
bobot.keyRelease(KeyEvent.VK_O);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_R);
bobot.keyRelease(KeyEvent.VK_R);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_L);
bobot.keyRelease(KeyEvent.VK_L);
bobot.delay(200);
bobot.keyPress(KeyEvent.VK_D);
bobot.keyRelease(KeyEvent.VK_D);
bobot.delay(200);


// ctrl+shift+F 格式化l
bobot.keyPress(KeyEvent.VK_SHIFT);
bobot.keyPress(KeyEvent.VK_CONTROL);
bobot.keyPress(KeyEvent.VK_F);
bobot.keyRelease(KeyEvent.VK_SHIFT);
bobot.keyRelease(KeyEvent.VK_CONTROL);
bobot.keyRelease(KeyEvent.VK_F);


// ctrl+S儲存
bobot.keyPress(KeyEvent.VK_CONTROL);
bobot.keyPress(KeyEvent.VK_S);
bobot.keyRelease(KeyEvent.VK_S);
bobot.keyRelease(KeyEvent.VK_CONTROL);

// F11執行
bobot.keyPress(KeyEvent.VK_F11);
bobot.keyRelease(KeyEvent.VK_F11);
}
}


參考JDK robot API,基本上鍵盤上所有按鍵都有,可以擴充套件寫出自動程式;