如何在Python(2.7)中运行自动热键脚本
我试图在Python2.7中运行一个自动热键(ahk)脚本,但似乎没有任何效果。我找到的所有在线资源要么已经过时,要么过于复杂 有人找到了这样做的方法吗?我只想运行几个简单的脚本来激活windows并打开应用程序。例如:如何在Python(2.7)中运行自动热键脚本,python,windows,python-2.7,autohotkey,Python,Windows,Python 2.7,Autohotkey,我试图在Python2.7中运行一个自动热键(ahk)脚本,但似乎没有任何效果。我找到的所有在线资源要么已经过时,要么过于复杂 有人找到了这样做的方法吗?我只想运行几个简单的脚本来激活windows并打开应用程序。例如: IfWinExist, Command Prompt - python ... WinActivate 更新: 我试过下载pyahk: ahk.start() # Ititializes a new script thread ahk.ready() # Waits
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_错误无效的类字符串似乎您应该能够使用以下命令以脚本作为参数启动自动热键:
您必须检查自动热键文档,但这似乎应该会起作用。我已将其作为一个编辑器添加,但效果良好!谢谢没想到会这么容易:)另外,我的.ahk文件实际上不起作用,但我只是在一个简单的hello World上试用了一下,没问题!奥卡姆的剃刀和所有的东西;有时候最简单的解决方案就是最好的!
subprocess.call(["path/to/ahk.exe", "script.ahk"])