【问题标题】:Does anyone know how to change from AutoIT code to Java? [closed]有谁知道如何从 AutoIT 代码更改为 Java? [关闭]
【发布时间】:2016-06-12 22:42:32
【问题描述】:

我有以下 AutoIT 代码,我想知道如何迁移/翻译成 Java

汽车信息技术:

   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());
        }
    }

有人可以帮帮我吗?

【问题讨论】:

  • 为什么你的代码不起作用?请附上您的错误信息。正如所写,有些人可能认为您要求 SO 为您提供编码服务。
  • 那么,错误是什么?发生了什么?还是没有发生?
  • 大家好,目前没有被执行,所以什么也没有发生,可能是我的 java 代码有问题

标签: java autoit


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-06
    • 2014-10-23
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2018-10-27
    相关资源
    最近更新 更多