【问题标题】:Calling AutoIt Functions in Python [closed]在 Python 中调用 AutoIt 函数 [关闭]
【发布时间】:2011-03-19 02:39:29
【问题描述】:

我看到this post 提到有一个 AutoIt3 COM 版本,有了它我可以在 Python 中调用 AutoIt 函数。

我在 AutoIt 网站上找不到 COM 版本。它隐藏在某个地方吗?我怎么才能得到它?

【问题讨论】:

    标签: python autoit


    【解决方案1】:

    如何在python中使用AutoItX COM/DLL

    在 Python 中使用 AutoIt 有两种方法:

    1. pyautoit module
    2. python for windows extentions (pywin32)

    pyautoit 模块将使用 DLL,而使用 pywin32 我们可以使用 COM。据我所知,两者在功能上没有区别。

    先决条件

    1. python 的安装。
    2. AutoIt 的安装。
    3. pyautoitpywin32 的安装。

    并非所有 AutoIt 功能都可通过 COM/DLL 接口使用。要查看哪些功能,请参阅 AutoItX 上的帮助文件。

    Pyautoit

    通过 pip 或您喜欢的方法安装:

    pip install -U pyautoit
    

    如果在安装 pyautoit 时遇到错误:WindowsError: [Error 193] %1 is not a valid Win32 application,请使用 32 位版本的 python。我无法使用 64 位版本的 python 安装 pyautoit。当然,您的里程可能会有所不同。

    导入和使用:

    import autoit
    
    autoit.run("notepad.exe")
    autoit.win_wait_active("[CLASS:Notepad]", 3)
    autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
    autoit.win_close("[CLASS:Notepad]")
    autoit.control_click("[Class:#32770]", "Button2")
    

    autoit 命令都使用 lower_case_with_underscores 而不是 AutoItX 的首选 CamelCase。因此 ControlSend 变成 control_send,WinClose 变成 win_close 等等。

    Pywin32

    安装 pywin32 后,通过以下方式调用 AutoItX 函数:

    import win32com.client
    autoit = win32com.client.Dispatch("AutoItX3.Control")
    
    autoit.Run("NotePad.exe")
    autoit.ControlClick(WINDOW, "", "[CLASSNN:TTreeView1]", "left", 1, 53, 41)
    

    如果您在使用此版本时遇到问题,请将所有内容安装为 32 位并重试。

    【讨论】:

    • 你知道在哪里可以找到 PyAutoIt 文档或教程吗?
    • @Mawg 我不确定这是否还有帮助,但我找到了这个 AutoItX COM/DLL 文档:documentation.help/AutoItX
    【解决方案2】:

    AutoItX.dllAutoItX3_x64.dll 包含在默认安装中,位于名为“AutoItX”的目录中。查看该目录中的帮助文件AutoItX.chm 了解更多信息。

    【讨论】:

    • 在 windows 7 中以管理员身份运行 cmd 转到 AutoItX.dll 并执行 regsvr32.exe AutoItX3.dll
    • 同时运行 regsvr32.exe AutoItX3_x64.dll 。可能会有帮助。
    猜你喜欢
    • 2013-11-25
    • 1970-01-01
    • 2022-01-20
    • 2020-12-14
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多