在這裏,我試圖用Java在AutoIt中打開記事本。但是我無法用下面的代碼打開它。無法在AutoIt中用Java打開記事本
public class Notepad {
public static String jvmBitVersion() { //returning the JVM Version
return System.getProperty("sun.arch.data.model");
}
public static void main(String[] args) throws InterruptedException {
String jacobDllVersionToUse;
System.out.println("JVM version is: " +jvmBitVersion());
if (jvmBitVersion().contains("32")) { //Checking for the JVM Version
jacobDllVersionToUse = "jacob-1.18-M2-x86.dll"; // If the version is 32- bit use this.
}
else { // enter code here
jacobDllVersionToUse = "jacob-1.18-M2-x64.dll"; // if the version is 64-bit go for this
}
File file = new File("lib", jacobDllVersionToUse); // file location for jacob
System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
AutoItX x = new AutoItX();
x.run("notepad.exe"); // trying to open the notepad
x.winActivate("Untitled - Notepad"); // waiting for the notepad to open
x.winWaitActive("Untitled - Notepad");
x.send("This is some text"); // Once the notepad is open write into it.
}
}
如果代替notepad.exe我給calc.exe它工作正常。如果我在運行這個代碼後手動打開記事本,它會寫入記事本。
謝謝。這對我有用。 –
@AnubhavMishra我用Notepad ++的例子更新了我的答案。 – SubOptimal