2016-04-13 12 views
2

ここでは、JavaでAutoItでメモ帳を開こうとしています。しかし、私は次のコードでそれを開くことができません。JavaでAutoItでメモ帳を開くことができません

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を指定しても問題ありません。これを実行した後にメモ帳を手動で開くと、メモ帳に書き込まれます。

答えて

2

すぐにノートパッドを起動すると、shownがこの問題を解決します。

メモ帳

AutoItX x = new AutoItX(); 
x.run("notepad.exe", "", AutoItX.SW_SHOW); 
x.winActivate("Untitled - Notepad"); 
x.winWaitActive("Untitled - Notepad"); 
x.send("This is some text"); 

Notepad++

AutoItX x = new AutoItX(); 
x.run("C:\\Program Files (x86)\\Notepad++\\notepad++.exe"); 
x.winActivate("[CLASS:Notepad++]"); 
x.winWaitActive("[CLASS:Notepad++]"); 
x.send("This is some text"); 
+0

ありがとうございます。これは私のために働いています。 –

+1

@AnubhavMishra私はメモ帳++の例を使って答えを更新しました。 – SubOptimal

1

フルパスを試してみてください:

x.run("C:\Windows\System32\notepad.exe") 

そして、あなたは存在しない「」と、アクティブにするために賢くなり、ウィンドウをアクティブにすることはできませんので、私は、あなたの待機コマンドの異なる順序を使用しますsend()コマンドを使用する前のウィンドウ。正しい順序次のようになります。

x.winWaitActive("Untitled - Notepad"); 

x.winActivate("Untitled - Notepad"); 
x.send("This is some text"); 

ます。また、(のみWinWaitを使用することができます)

1

このコードは、私の作品:ウィンドウのタイトルは、Windowsアプリケーションと一致しなければならないということ

AutoItX x = new AutoItX(); 
x.run("notepad.exe", "C:/Windows/System32/", AutoItX.SW_SHOW); // trying to open the notepad 

x.winActivate("Sin título: Bloc de notas"); // waiting for the notepad to open 
x.winWaitActive("Sin título: Bloc de notas"); 
x.send("This is some text"); // Once the notepad is open write into it. 

お知らせ。私の場合、Windowsはスペイン語でタイトルは "Sintítulo:Bloc de notas"です。

関連する問題