使用 autoHotKey 代码,如何编写一个函数来接收 autohotkey 命令文本作为参数并执行它?

With autoHotKey code, how can I write a function that receives the autohotkey command text as a parameter and executes it?

提问人:Won Jin Kim 提问时间:9/7/2023 更新时间:9/10/2023 访问量:48

问:

例如,我想将任何 ahk 命令文本(如“Click, 50, 50”或“MsgBox test”,,,传递到函数中并执行该命令。可能吗?

函数 参数 命令 autohotkey

评论


答:

2赞 Dieisson Silva dos Santos 9/10/2023 #1

这可能会对您有所帮助。

#SingleInstance, Force

    var := "example"
    new_instance(   "msgbox " var " 1`nexitapp" )
    new_instance(   "msgbox % ""another " var " 2"""
                .   "`nexitapp" )
    new_instance(   "msgbox another example 3`nexitapp" )
    new_instance(   "msgbox passing var`n"
                .   "var := """ var " 4""`n"
                .   "Msgbox % var `n"
                .   "exitapp" )

ExitApp, 0

new_instance( Script )  {

    OutputDebug, % script   ;   for debug purpose
    shell   := ComObjCreate( "WScript.Shell" )
    exec    := shell.Exec( A_AhkPath " /ErrorStdOut *")
    exec.StdIn.Write( script )
    exec.StdIn.Close()

}

评论

0赞 Won Jin Kim 9/11/2023
一切顺利。我认为这是一个不可能的功能。我很感激。
0赞 Won Jin Kim 9/11/2023
但不应该是“MouseMove,10,10,Relative”的情况吗?我收到错误。该代码是否适用于所有其他 AHK 命令?
0赞 Dieisson Silva dos Santos 9/11/2023
new_instance( “MouseMove, 10, 10, Relative'nexitapp” ) 它在 1.1.36.02 V1 上对我来说效果很好。它适用于任何代码,但请务必注意,发送到此函数的每个代码都被视为一个新实例。因此,建议仔细查看输出代码。你能发布你的函数调用吗?
0赞 Won Jin Kim 9/12/2023
我一定做错了什么。现在这太好了。我很感激
0赞 Won Jin Kim 9/12/2023
此脚本是否可以在未安装自动热键的环境中运行?这是因为在未安装自动热键的环境中,A_AhkPath部分似乎存在错误。我只需要自动热键 .exe 文件吗?