在 Python 中调用 AutoIt 函数

发布于 2024-09-10 11:51:15 字数 1539 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方觉久 2024-09-17 11:51:15

如何在 python 中使用 AutoItX COM/DLL

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

  1. pyautoit 模块
  2. 用于 Windows 扩展的 python (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 位,然后重试。

How to use AutoItX COM/DLL in python

There are two methods for using AutoIt in Python:

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

The pyautoit module will make use of the DLL while with pywin32 we can use the COM. As far as I know, there is no functional difference between the two.

Prerequisites

  1. An installation of python.
  2. An installation of AutoIt.
  3. An installation of either pyautoit or pywin32.

Not all AutoIt functions are available through the COM/DLL interface. To see which functions are, see the help file on AutoItX.

Pyautoit

Install via pip or your preferred method:

pip install -U pyautoit

If you get an error: WindowsError: [Error 193] %1 is not a valid Win32 application when installing pyautoit, use the 32 bit version of python. I haven't been able to get pyautoit to install using the 64 bit version of python. Of course, your mileage may vary.

Import and use:

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")

The autoit commands all use lower_case_with_underscores rather than AutoItX's preferred CamelCase. Thus ControlSend becomes control_send, WinClose becomes win_close, etc.

Pywin32

Once pywin32 is installed, call AutoItX functions by:

import win32com.client
autoit = win32com.client.Dispatch("AutoItX3.Control")

autoit.Run("NotePad.exe")
autoit.ControlClick(WINDOW, "", "[CLASSNN:TTreeView1]", "left", 1, 53, 41)

If you have trouble with this version, install everything as 32 bit and try again.

友欢 2024-09-17 11:51:15

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

AutoItX.dll and AutoItX3_x64.dll are included in the default installation, in a directory called "AutoItX". Check out the help file AutoItX.chm in that directory for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文