自己用Java寫的一個程序,運行代碼後6秒內(時間可更改)將遊標移入文本框即可(QQ、微信聊天發送框等)
代碼如下:
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;
class QQ {
public void dosomething() {
//使用map 將控制鍵盤的常量存起來,好方便取用。
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(0, 0x30);//鍵盤的0
map.put(1, 0x31);//鍵盤的1
map.put(2, 0x32);//鍵盤的2
map.put(3, 0x33);//鍵盤的3
map.put(4, 0x34);//鍵盤的4
map.put(5, 0x35);//鍵盤的5
map.put(6, 0x36);//鍵盤的6
map.put(7, 0x37);//鍵盤的7
map.put(8, 0x38);//鍵盤的8
map.put(9, 0x39);//鍵盤的9
try {
Robot robot = new Robot();
robot.delay(6000);//延遲6秒供你打開編輯器,時間可更改
//讓機器從0數到200(數字可以更改,最大爲999)
for (int i = 0; i < 201; i++) {
// 個位數的處理
if (i <= 9) {
robot.keyPress(map.get(i));
robot.keyPress(KeyEvent.VK_ENTER);
}
// 兩位數的處理
if (i > 9 && i <= 99) {
int a = i / 10;// 十位
int b = i % 10;// 個位
robot.keyPress(map.get(a));
robot.keyPress(map.get(b));
robot.keyPress(KeyEvent.VK_ENTER);
}
// 三位數的處理
if (i > 99 && i <= 200) {
int a = i / 100;// 百位
int b = (i % 100) / 10;// 十位
int c = i % 10;// 個位
robot.keyPress(map.get(a));
robot.keyPress(map.get(b));
robot.keyPress(map.get(c));
robot.keyPress(KeyEvent.VK_ENTER);
}
}
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
QQ bh = new QQ();
bh.dosomething();
}
}
注:數字不是順序發出
萌新小白,正在學習階段,發表代碼爲了可以交流交流經驗
代碼如有雷同,可聯繫我刪除本文章(如有冒犯,望見諒)