How to run an autohotkey script in Python (2.7)

柔情痞子 提交于 2021-01-27 14:07:53

问题


I'm trying to run an autohotkey (ahk) script in Python 2.7 but nothing seems to work. All online sources I've found are either outdated or overly complicated.

Has anyone found a way of doing this? I just want to run a couple of simple scripts that activates windows and opens applications. E.g:

IfWinExist, Command Prompt - python ...
    WinActivate

Update:

I've tried downloading 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

error: can't load autohotkey.dll

as well as trying this:

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 invalid class string


回答1:


It seems like you should be able to just launch autohotkey with the script as a parameter using subprocess:

subprocess.call(["path/to/ahk.exe", "script.ahk"])

You'd have to check the autohotkey docs but this seems like it ought to work.



来源:https://stackoverflow.com/questions/36652169/how-to-run-an-autohotkey-script-in-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!