我正在尝试制作一个从我那里获取输入的小型Java应用程序,打开另一个应用程序( Windows Calculator /“calc”)并使用我的输入提供该应用程序。
目前,我正在尝试对简单的Windows计算器执行此操作,但它似乎不适用于传统方法:
public Feeder(String processID) throws Exception {
rt = Runtime.getRuntime();
proc = rt.exec("calc");
input = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
}
public void sendCommand(int cmd) throws Exception {
input.write(cmd);
input.flush();
input.close();
proc.waitFor();
}
(Partially taken from another source, credit due to author)
但是,与上面发送到另一个命令行进程的代码相反,WinCalc是图形化的。是否仍然可以向其发送输入而无需经历逆向工程等各种麻烦?
答案 0 :(得分:3)
您可以使用java.awt.Robot将文本发送到当前活动窗口,然后移动并单击鼠标。如果您需要更高级的消息传递,那么您将需要JNI或(我的推荐)JNA。
其他选项包括将您的应用程序绑定到AutoHotKey或AutoIt V3。
我自己,我已经成功运行了JNA,Robot和AutoIt的其他应用程序,使用了最适合这种情况的应用程序。