模拟键盘打开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);
}
七号时光机
发布了5 篇原创文章 · 获赞 0 · 访问量 89
私信
关注
标签:keyRelease,KeyEvent,keyPress,VK,notepad,robot,键盘,模拟 来源: https://blog.csdn.net/weixin_40423282/article/details/103952654