如何在Python(2.7)中运行自动热键脚本 [英] How to run an autohotkey script in Python (2.7)

查看:67
本文介绍了如何在Python(2.7)中运行自动热键脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python 2.7中运行自动热键(ahk)脚本,但似乎无济于事.我发现的所有在线资源都已经过时或过于复杂.

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.

有人找到这样做的方法吗?我只想运行几个简单的脚本来激活Windows并打开应用程序.例如:

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

更新:

我尝试下载pyahk:

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

错误:无法加载autohotkey.dll

error: can't load 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无效的类字符串

pwintypes.com_error invalid class string

推荐答案

似乎您应该能够使用

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"])

您必须检查autohotkey文档,但这似乎应该可以工作.

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

这篇关于如何在Python(2.7)中运行自动热键脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆