Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling AutoIt Functions in Python [closed]

Tags:

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

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

like image 842
Wang Dingwei Avatar asked Jul 21 '10 16:07

Wang Dingwei


People also ask

How do I run an AutoIt script from the command line?

Run a script using another compiled script:Compiled.exe [/ErrorStdOut] /AutoIt3ExecuteScript file [params ...] Execute another AutoIt script file from a compiled AutoIt3 executable. Execute one line of code as with AutoIt3.exe above.

What is AutoIt in Python?

AutoIt is a freeware scripting language designed for automating windows GUI and general scripting. It uses a combination of mouse movement, keystrokes and window control manipulation to automate a task which is not possible by selenium webdriver.

How do I open an AutoIt script?

Pressing Ctrl-F5 will run Tylo's AutoIt3 syntax checker, which will syntax check the script. Pressing just F5 will run Au3Check and then, if no errors/warnings are found, run AutoIt3.exe to run the script.


2 Answers

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.

like image 180
cledoux Avatar answered Sep 19 '22 12:09

cledoux


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.

like image 21
ewall Avatar answered Sep 20 '22 12:09

ewall