有没有办法让AutoHotKey输入我的.java文件的输出?有谁能提供见解吗?例如,如果我的hat.txt文件包含:
纸石剪刀
我如何输入一个AHK按键(Ctrl + g),并让它输入“剪刀”或任何我的.java文件的输出?
到目前为止,我可以将一个AHK脚本映射到一个键(Ctrl + g)。然后出现DOS窗口并关闭。我编写的.java文件有(它在JGrasp中编译时没有错误。它需要一个简单的hat.txt记事本文件来处理。):
/* Created by John Thrush 7/20/16
MagicHat.java scans a simple Hat.txt file line by line
and randomly selects one line to display in an applet.
Put anything you like into the hat and pull out a rabbit.
*/
import java.io.*;
import java.util.*;
import java.io.FileNotFoundException;
import javax.swing.*;
import java.awt.Font;
public class MagicHat
{
public static void main(String [] args)
{
try
{
BufferedReader reader = new BufferedReader(new FileReader("hat.txt"));
String line = reader.readLine();
List<String> listOfLines = new ArrayList<String>();
while (line != null)
{
listOfLines.add(line.replace("\t", " "));
line = reader.readLine();
}
Random r = new Random();
String randomLine = listOfLines.get(r.nextInt(listOfLines.size()));
JLabel label = new JLabel(randomLine);
label.setFont(new Font("Trebuchet MS", Font.BOLD, 28));
JOptionPane.showMessageDialog(null,label,"Magic Hat",JOptionPane.PLAIN_MESSAGE);
System.out.println(randomLine);
// listOfLines.remove(randomLine); //remove this line if you don't want to randomly choose items more than once
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null,e.getMessage()+" for hat.txt","File Error",JOptionPane.ERROR_MESSAGE);
}
System.exit(0);
}
}我的AHK测试文件有(这是我对AHK语法非常了解的情况下最好的猜测):
;JavaTest
^g::Run,java -cp MagicHat.class,C:\Users\MyPC\Desktop\John Thrush\Java JFT\CompleteCode
发布于 2017-08-26 01:50:37
如果您希望将来自Java的System.out.println()的控制台输出存储到文本文件中,只需使用:
C:\> java myProgram > output.txt所有应该在控制台上显示的输出都将保存到命令中声明的文本文件中。
由于您已经打开命令提示符来运行java程序,因此只需将输出重定向的命令添加到一个文本文件中。
https://stackoverflow.com/questions/45886888
复制相似问题