PYAHK AutoHotKey via Python¶
|Description:||Python ctypes wrapper around AutoHotKey dll.|
|License:||BSD-style, see LICENSE.txt|
|Author:||Ed Blake <firstname.lastname@example.org>|
|Date:||Dec 30 2014|
AutoHotKey is a powerful task automator with a terrible scripting language built-in. Python is a powerful scripting language with old, unmaintained, and incomplete automation modules. Combining the two creates a powerful automation tool with a powerful scripting back-end with access to all the power of the Python standard library.
This is made possible by the amazing Python ctypes module and the AutoHotKey.dll project. Together they allow exchange of data between both scripting engines, and the execution of AHK commands from Python.
- Written for Python2.7, not currently py3k compatible.
- Written against AutoHotkey_H ANSI 32-bit Version 126.96.36.199 (on WinXP).
- A copy of the ANSI 32-bit dll must be provided either in the system location of your version of Windows, or in the same folder as the ahk.py file. (The required dll is not provided as part of this distribution, see the AutoHotKey.dll site for download instructions (alternate link AutoHotKey_H).)
Get the version from PyPI using pip:
pip install pyahk
Or download the latest commit from bitbucket and:
`python setup.py install`
A helper script “runtests.py” is provided in the project root to run the entire test suite. Runnable test scripts are provided for each sub-module in the test folder. Tests require Michael Foord’s mock library.
First import the ahk module:
Lower level function wrappers provide more direct access to the underlaying dll:
ahk.start() # Ititializes a new script thread ahk.ready() # Waits until status is True ahk.execute('a := WinActive("Notepad")') # Sets a to the return value of WinActive print ahk.get('a') # prints the HWND of the found window or 0x0 as a string
Object wrappers are also provided which have a somewhat cleaner interface:
script = ahk.Script() # Initializes with start and ready commands as above a = script.winActive("Notepad") # Sets a to the return value of the method print a # prints the HWND of the found window as an int, or None script.variable('b', float) # Creates a transparent variable attribute ahk.execute("Random, b, 0.0, 1.0") # Stores value in `b` print 100*script.b # b is retrieved and converted to its saved type (float)
See the Docs for further details.
- Re-write script.Function to use the now working ahk.call function.
- Extend setup script with options to download/install the correct dll?
- Add remaining Control commands to Control class.
- Add doc-tests?
- Extend Script class with something to replace ahk.execute (maybe some kind of subroutine wrapper?).
- Add examples directory.
- Add optional unicode support.