Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

PYAHK AutoHotKey via Python

Description:Python ctypes wrapper around AutoHotKey dll.
License:BSD-style, see LICENSE.txt
Author: Ed Blake <kitsu.eb@gmail.com>
Date: May 19 2013
Revision: 13

Introduction

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.

Requirements

  • Written for Python2.7, not currently py3k compatible.
  • Written against AutoHotkey_H ANSI 32-bit Version 1.1.8.1 (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.)

Installation

Get the version from PyPI using pip:

pip install pyahk

Or download the latest commit from bitbucket and:

`python setup.py install`

Testing

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.

Usage

First import the ahk module:

import ahk

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 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.

ToDo

  • 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.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.