如何 运行 Python 中的自动热键脚本 (2.7)

How to run an autohotkey script in Python (2.7)

我正在尝试 运行 Python 2.7 中的自动热键 (ahk) 脚本,但似乎没有任何效果。我发现的所有在线资源都已过时或过于复杂。

有没有人找到这样做的方法?我只想 运行 几个激活 windows 和打开应用程序的简单脚本。例如:

IfWinExist, Command Prompt - python ...
    WinActivate

更新:

我试过下载 pyahk:

ahk.start() # Ititializes a new script thread
ahk.ready() # Waits until status is True
ahk.execute(mw._['cwd']+"winActivate_cmd.ahk") # Activate cmd window

错误:无法加载 autohotkey.dll

以及尝试这个:

import win32com.client # Import library / module
dll = win32com.client.Dispatch("AutoHotkey.Script") #Creating DLL object?
dll.ahktextdll() #no idea what this is doing...        
dll.ahkExec("WinActivate, Command Prompt - python")

pwintypes.com_error无效class字符串

看来您应该能够使用 subprocess:

将脚本作为参数启动 autohotkey
subprocess.call(["path/to/ahk.exe", "script.ahk"])

您必须查看 autohotkey 文档,但这似乎应该有效。