无论如何都要从JAVA进程输入notepad.exe进程吗?
答案 0 :(得分:15)
是的,使用机器人是解决方案:
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Notepad {
static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V,
KeyEvent.VK_A, KeyEvent.VK_SPACE };
public static void main(String[] args) throws Exception {
Runtime.getRuntime().exec("notepad");
Robot robot = new Robot();
for (int i = 0; i < keyInput.length; i++) {
robot.keyPress(keyInput[i]);
robot.delay(100);
}
}
}
如果要将String转换为keyEvents,请检查此问题 Convert String to KeyEvents