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

问题描述 投票:0回答:1

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

function parameters command autohotkey
1个回答
0
投票

这可能对你有帮助。

#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()

}
© www.soinside.com 2019 - 2024. All rights reserved.