在Python中调用AutoIt函数 [英] Calling AutoIt Functions in Python
问题描述
我看过这篇文章提到有一个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:
- pyautoit module
- python for windows extentions (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.
- An installation of python.
- An installation of AutoIt.
- 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.我无法使用python 64位版本获取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屋!