我正在制作Java程序,为您键入预定义的消息。我不断收到getRuntime
和exec
的错误消息。我试图搜索谷歌,但一无所获。我尝试更改项目中的设置并添加“throws”,但似乎没有任何效果。我是java的新手,所以请你好。
这是我目前的代码:
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class main {
Runtime getRuntime() exec("notepad.exe");
Thread.sleep(2000);
Robot r=new Robot();
r.keyPress(KeyEvent.VK_T);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_H);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_I);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_S);
Thread.sleep(750);
r.keyPress(KeyEvent.VK_SPACE);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_I);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_S);
Thread.sleep(750);
r.keyPress(KeyEvent.VK_SPACE);
Thread.sleep(650);
r.keyPress(KeyEvent.VK_F);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_U);
Thread.sleep(500);
r.keyPress(KeyEvent.VK_N);
}}
答案 0 :(得分:1)
尝试Runtime.getRuntime().exec("notepad.exe");