有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

有人知道如何从AutoIT代码更改为Java吗?

我有以下AutoIT代码,我想知道如何迁移/转换到Java

自动IT:

   AutoItSetOption("WinTitleMatchMode","20")
   WinWait("Authentication Required")
   While WinExists("Authentication Required")
      Opt("SendKeyDelay", 50)
      $title = WinGetTitle("Authentication Required") ; retrieves whole window title
      $UN=WinGetText($title,"User Name:")
      ControlSend($title,"",$UN,"myemail@gmail.com{TAB}");Sets Username and {TAB}
      $PWD=WinGetText($title,"Password:")
      ControlSend($title,"",$PWD,"mypassword");Sets PWD  and {ENTER}
      ControlSend($title,"",$PWD,"{ENTER}");
      Sleep(2000)
   WEnd
   Exit

这就是我试图转换为Java的内容:

public void shouldEnterCredentials() throws Throwable {
        try {
            File file = new File("lib", "jacob-1.18-x64.dll"); //path to the jacob dll
            System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

            AutoItX x = new AutoItX();
            String title = x.winGetTitle("Authentication Required");
            String un = x.winGetText(title,"User Name:");
            String pwd = x.winGetText(title,"Password:");

            x.autoItSetOption("WinTitleMatchMode","20");
            x.winWait("Authentication Required");
            while (x.winExists("Authentication Required")){
               x.autoItSetOption("OPT_SEND_KEY_DELAY", "50");
               x.controlSend(title,"", un, "myemail@gmail.com{TAB}"); //Sets Username and {TAB}
               x.controlSend(title,"",pwd,"mypassword"); //Sets PWD  and {ENTER}
               x.controlSend(title, "", pwd,"{ENTER}");
               x.sleep(2000);
            }       

        } catch (Exception e) {
            System.out.println("Error: " + e.getStackTrace());
        }
    }

有人能帮我吗


共 (1) 个答案

  1. # 1 楼答案

    为什么不编译AutoIt代码并从Java代码中运行它呢

    您的AutoIt代码不会返回任何内容,因此编译AutoIt脚本并从中执行批处理文件更容易(也更可靠)