python - 如何在 Python (2.7) 中运行自动热键脚本

标签 python windows python-2.7 autohotkey

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

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

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 无效类字符串

最佳答案

看来您应该能够使用 subprocess 将脚本作为参数来启动 autohotkey :

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

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

关于python - 如何在 Python (2.7) 中运行自动热键脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36652169/

相关文章:

python - 在python中从unicode(对于外语)段落中提取主题标签

windows和apache下的Python作为FastCGI

c# - PowerShell 和 C# ASP.NET 之间的管道传输

c++ - 如何在Win32 C++中进行打印预览?

python - django-admin startproject 不能在 OS X 上使用 python3

python - XML 写入文件 UnicodeDecodeError Python 2.7.3

python - Azure 批处理池 : How do I use a custom VM Image via Python?

python - 不受信任的用户可以安全使用哪个 Python 模板引擎?

python - 使用py2exe在.exe中嵌入图标,在Vista中可见?

python - *** key 错误 : 'font-family' on replacing a html string into another html string