模拟键盘打开notepad

public static void notepad()throws Exception{
Process exec = Runtime.getRuntime().exec(“notepad”);
System.out.println(“start notepad”);
// System.setProperty(“java.awt.headless”, “true”);
Robot robot=new Robot();
robot.delay(1000);
System.out.println(“start keypress”);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_T);

    robot.keyPress(KeyEvent.VK_E);
    robot.keyRelease(KeyEvent.VK_E);

    robot.keyPress(KeyEvent.VK_S);
    robot.keyRelease(KeyEvent.VK_S);

    robot.keyPress(KeyEvent.VK_T);
    robot.keyRelease(KeyEvent.VK_T);

    robot.keyPress(KeyEvent.VK_SPACE);
    robot.keyRelease(KeyEvent.VK_SPACE);
    robot.delay(1000);
    //ctrl+shift+F 格式化
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_S);
    robot.delay(500);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_S);

}
模拟键盘打开notepad模拟键盘打开notepad 七号时光机 发布了5 篇原创文章 · 获赞 0 · 访问量 89 私信 关注
上一篇:0176 常用的键盘事件:keyup,keydown,keypress


下一篇:[转载] Kotlin 泛型