當前位置:首頁 » 編程語言 » javarobot

javarobot

發布時間: 2024-06-02 21:02:09

① 濡備綍鐢↗ava Robot鏉ュ疄鐜版墜鏈烘帶鍒剁數鑴戱紵

java涓鐢≧obot綾繪帶鍒墮紶鏍囧拰閿鐩樼殑鏂規硶
http://www.c114.net ( 2007/8/17 00:00 )

Java.awt.Robot 綾葷敤浜庢帶鍒墮紶鏍囧拰閿鐩樸備竴鏃︿綘寰楀埌榪欑嶆帶鍒訛紝浣犺兘澶熼氳繃浣犵殑Java浠g爜鍋氫笌榧犳爣鍜岄敭鐩樹換浣曠被鍨嬬殑鎿嶄綔銆傝繖涓綾婚氬父鐢ㄤ簬鑷鍔ㄥ寲嫻嬭瘯銆備笅闈㈢殑浠g爜鏍蜂緥灝嗗悜鎮ㄥ睍紺篟obot綾誨備綍澶勭悊閿鐩樹簨浠躲傚傛灉浣犺繍琛屾や唬鐮侊紝騫舵墦寮notepad錛屾偍灝嗗湪notepad涓鐪嬪埌HI CAOER.璧跺揩璇曚竴璇曞惂銆

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotExp {
public static void main(String[] args) {
try {
Robot robot = new Robot();
//瀹氫箟5縐掔殑寤惰繜浠ヤ究浣犳墦寮notepad
// Robot 寮濮嬪啓
robot.delay(5000);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_C);
robot.keyPress(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_O);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_R);
} catch (AWTException e) {
e.printStackTrace();
}
}
}

緗戝弸瀹屽杽浜嗕互涓婁唬鐮侊細

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.IOException;

public class RobotExp {
public static void pressKey(Robot robot, int keyvalue) {
robot.keyPress(keyvalue);
robot.keyRelease(keyvalue);
}
public static void pressKeyWithShift(Robot robot, int keyvalue) {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(keyvalue);
robot.keyRelease(keyvalue);
robot.keyRelease(KeyEvent.VK_SHIFT);
}
public static void closeApplication(Robot robot) {
// pressKey(robot, KeyEvent.VK_ALT);
// pressKey(robot, KeyEvent.VK_F4);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F4);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_F4);
//for linux.
// robot.keyPress(KeyEvent.VK_ALT);
// robot.keyPress(KeyEvent.VK_W);
// robot.keyRelease(KeyEvent.VK_ALT);
// robot.keyRelease(KeyEvent.VK_W);
robot.keyPress(KeyEvent.VK_N);
robot.keyRelease(KeyEvent.VK_N);
}
public static void main(String[] args) throws IOException {
try {
Robot robot = new Robot();
Runtime.getRuntime().exec("notepad");
// For linux.
//Runtime.getRuntime().exec("gedit");
//瀹氫箟5縐掔殑寤惰繜浠ヤ究浣犳墦寮notepad 鍝堝搱
// Robot 寮濮嬪啓
robot.delay(3000);
for (int i = 0; i < 100; i++) {
pressKeyWithShift(robot, KeyEvent.VK_H);
pressKey(robot, KeyEvent.VK_I);
pressKey(robot, KeyEvent.VK_SPACE);
//pressKeyWithShift(robot, KeyEvent.VK_H);
pressKeyWithShift(robot, KeyEvent.VK_I);
pressKey(robot, KeyEvent.VK_SPACE);
pressKey(robot, KeyEvent.VK_A);
pressKey(robot, KeyEvent.VK_M);
pressKey(robot, KeyEvent.VK_SPACE);
pressKey(robot, KeyEvent.VK_T);
pressKey(robot, KeyEvent.VK_H);
pressKey(robot, KeyEvent.VK_E);
pressKey(robot, KeyEvent.VK_SPACE);
pressKey(robot, KeyEvent.VK_J);
pressKey(robot, KeyEvent.VK_A);
pressKey(robot, KeyEvent.VK_V);
pressKey(robot, KeyEvent.VK_A);
pressKey(robot, KeyEvent.VK_SPACE);
pressKey(robot, KeyEvent.VK_R);
pressKey(robot, KeyEvent.VK_O);
pressKey(robot, KeyEvent.VK_B);
pressKey(robot, KeyEvent.VK_O);
pressKey(robot, KeyEvent.VK_T);
// VK_ENTER
pressKey(robot, KeyEvent.VK_ENTER);
//pressKey(robot, KeyEvent.);
}
closeApplication(robot);
//robot.keyPress(KeyEvent.VK_SPACE);
} catch (AWTException e) {
e.printStackTrace();
}
}
}

鏉ユ簮錛氳禌榪緗戞妧鏈紺懼尯 浣滆咃細dxaw
浣滆咃細 鏉ユ簮錛 0

熱點內容
ftp搭建win7 發布:2025-05-20 10:06:06 瀏覽:81
訪問堅果 發布:2025-05-20 10:06:02 瀏覽:393
ftpxlight 發布:2025-05-20 10:05:22 瀏覽:110
java的實驗報告 發布:2025-05-20 10:02:06 瀏覽:528
豪華配置高電動轎車有哪些 發布:2025-05-20 10:01:59 瀏覽:487
哪些電腦配置低 發布:2025-05-20 09:34:16 瀏覽:955
地板網站源碼 發布:2025-05-20 09:27:23 瀏覽:346
安卓視頻轉換器怎麼使用 發布:2025-05-20 09:20:52 瀏覽:544
telnet批量腳本 發布:2025-05-20 09:11:58 瀏覽:627
搭建jrebel伺服器 發布:2025-05-20 08:57:40 瀏覽:903