在 Python 中调用 AutoIt 函数 [英] Calling AutoIt Functions in Python

查看:42
本文介绍了在 Python 中调用 AutoIt 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过这篇文章提到有一个 AutoIt3 COM 版本,有了它我可以在 Python 中调用 AutoIt 函数.

I have seen this post mentioned there is an AutoIt3 COM version, and with it I can call AutoIt functions in Python.

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

I couldn't find the COM version at the AutoIt website. Is it hidden somewhere? How can I get it?

推荐答案

如何在python中使用AutoItX COM/DLL

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

How to use AutoItX COM/DLL in python

There are two methods for using AutoIt in Python:

  1. pyautoit 模块
  2. python 用于 Windows 扩展 (pywin32)

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

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.

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

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

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

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

Install via pip or your preferred method:

pip install -U pyautoit

如果在安装 pyautoit 时出现错误:WindowsError: [Error 193] %1 is not a valid Win32 application,请使用 32 位版本的 python.我无法使用 64 位版本的 python 安装 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 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 等

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 后,通过以下方式调用 AutoItX 函数:

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)

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

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

这篇关于在 Python 中调用 AutoIt 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆