问题
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