Last active
March 11, 2019 21:43
-
-
Save stephenmm/489c5d8c1249b10f23015b00fc46b270 to your computer and use it in GitHub Desktop.
autoit_python_with_cygwin.bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Being able to automate windows tasks with autoit is cool but it would be even cooler if we could: | |
# 1) run it with python (py is much easier and familiar than the autoit script language) | |
# 2) with cygwin (so we can do all our linux/bash/vim cleverness in a familiar work environment) | |
# | |
# Here is some info on how I got it set up on my new windows laptop. | |
# Some interesting reading on autoit functionality direclty from windows DLLs: https://stackoverflow.com/questions/23768184/programmatically-rotate-monitor | |
# Functions for win32api http://timgolden.me.uk/pywin32-docs/contents.html | |
# Directly calling the DLLs w/ ctypes: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getsystemmetrics | |
# Working example (double click from windows File Explorer): | |
/cygdrive/c/Users/$USER/examples/py/autoit_vnc_viewer.py | |
# Here is what I did to be able to call autoit dll from python: | |
# These links were very usefull: | |
https://stackoverflow.com/a/13396451/120681 | |
https://www.autoitscript.com/autoit3/docs/intro/64-bit_support.htm | |
cd 'C:\Program Files (x86)\AutoIt3\AutoItX\' | |
cp .\AutoItX3_x64.dll C:\Windows\System32\ | |
C:\Windows\System32\regsvr32.exe C:\Windows\System32\AutoItX3_x64.dll | |
pip install pypiwin32 | |
python | |
if "Run the calculator": | |
import win32com.client | |
Auto=win32com.client.Dispatch("AutoItX3.Control") | |
Auto.Run("calc.exe") | |
import time | |
time.sleep(1) | |
title = 'Calculator' | |
Auto.WinActivate(title, '') | |
time.sleep(1) | |
Auto.Send("12345") | |
time.sleep(0.4) | |
Auto.Send("{+}") | |
time.sleep(0.4) | |
Auto.Send("54321") | |
time.sleep(0.4) | |
Auto.Send("{=}") | |
time.sleep(0.4) | |
Auto.Send("^c") | |
time.sleep(1) | |
Auto.WinClose(title , '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment