import java.awt.Robot;
import java.awt.event.KeyEvent;
public class RobotUtil {
/**
* path 不支持汉字
* @param robot
* @param line
*/
public static void printString(Robot robot, String line) {
char[] keys = line.toUpperCase().toCharArray();
for (char c : keys) {
pressKey(robot, c);
}
}
public static void pressKey(Robot robot, char c) {
if (c == ':') {
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SEMICOLON);
robot.keyRelease(KeyEvent.VK_SHIFT);
} else {
int k = (int) c;
robot.keyPress(k);
robot.keyRelease(k);
}
}
/**
* @param args
*/
public static void main(String[] args) {
try {
String path = "c:/temp/form/a.html";
Robot robot;
robot = new Robot();
robot.delay(1000);
printString(robot, path);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}