AutoHotkey.py: Write AutoHotkey scripts in Python

Post your working scripts, libraries and tools for AHK v1.1 and older
Perlence
Posts: 9
Joined: 27 Jun 2020, 06:35
Contact:

AutoHotkey.py: Write AutoHotkey scripts in Python

24 Jan 2021, 05:04

AutoHotkey.py

AutoHotkey.py is a Python library that embeds a Python DLL into the AutoHotkey_L v1.1 process. It lets you call AHK functions from the Python code and register Python functions to be called from AHK, e.g. hotkeys, timers, clipboard handlers.

Goals of the project:
  • Friendly API and improved developer experience
  • Leveraging the Python ecosystem
Non-goals:
  • Compatibility with AutoHotkey down to function names
  • Using AutoHotkey.py as an AHK library
To get started, follow the GitHub link.

Examples

Show a message box and register an F1 hotkey:

Code: Select all

import sys
import ahkpy

ahkpy.message_box("Hello!")

@ahkpy.hotkey("F1")
def bye():
    ahkpy.message_box("Bye!")
    sys.exit()
Schedule a timer to close specific windows every 100 ms:

Code: Select all

import ahkpy

ahkpy.set_timer(0.1, lambda: ahk.windows.close_all(class_name="AnnoyingAdWindow"))
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: AutoHotkey.py: Write AutoHotkey scripts in Python

24 Jan 2021, 12:04

@Perlence, this is a very exciting project. Despite the stated requirements, it does run on Win7. For my Win7 Pro 64-bit system, Python 3.7.3, I needed to make the following changes to get the first github example to run from an admin command prompt (and I see that's exactly what you have above!):

playground.py:

Code: Select all

import sys
import ahkpy as ahk

ahk.message_box("Hello!")

@ahk.hotkey("F1")
def bye():
    ahk.message_box("Bye!")
    sys.exit()
From admin terminal, to run, as ahkpy is an executable:

Code: Select all

ahkpy playground.py
Also, I just installed via 'pip install autohotkey.py' from an admin command prompt rather than the method described on github.

Thank you very much for this! I'm looking forward eagerly to see this progress, and I'll try it out on Win10 Pro as well, with all the examples you've provided.
EDIT: I see there are extensive docs on GitHub as well. Great stuff.

Regards,
burque505
Perlence
Posts: 9
Joined: 27 Jun 2020, 06:35
Contact:

Re: AutoHotkey.py: Write AutoHotkey scripts in Python

24 Jan 2021, 14:26

Hello burque505! Thank you for trying it out! The minimum Windows version is due to the IsWow64Process2 call in the Window.send_message method. Apart from that, I think, most of the API should work on Windows 7. Also note that Python 3.8.x is the last Python release that supports Windows 7.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: AutoHotkey.py: Write AutoHotkey scripts in Python

24 Jan 2021, 14:44

@Perlence, thanks for the clarification, much appreciated.
Regards,
burque505
User avatar
joedf
Posts: 8988
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoHotkey.py: Write AutoHotkey scripts in Python

01 Feb 2021, 10:05

:wave: Only saw this now because of awesome-AutoHotkey. Very interesting stuff. :thumbup:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot] and 87 guests