python - 在 Python 中调用 AutoIt 函数

标签 python autoit

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

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

最佳答案

如何在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 接口(interface)使用。要查看哪些功能,请参阅 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 位并重试。

关于python - 在 Python 中调用 AutoIt 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3301561/

相关文章:

python - py.test main() 调用示例

python - 如何去除图像上的卷线

testing - AutoIt 中的组合键

autoit - 如何使用 AutoIt 按下 "ALT+F4"

updates - 自动添加一行文本到编辑框

python - 预览 PIL 图像的最快方法

python - Pygraphviz/networkx 设置节点级别或层

python - 插入 MySQL 失败并出现错误

c++ - 将 32 位 dll 注入(inject) 64 位进程 - Autoit 使之成为可能?

AutoIt:在鼠标指针下查找窗口