addScript

导出的函数将字符串中的新代码添加到当前执行的脚本中。


OutputVar := addScript(NewCode, WaitExecute)
函数示例: LinePtr := addScript("MsgBox `% A_Now", 1)
                  LinePtr := DllCall("AutoHotkey.dll\addScript", "Str", "MsgBox `% A_Now", "Int", 1, "UPTR")
                  LinePtr := DllCall("AutoHotkey.exe\addScript", "Str", "MsgBox `% A_Now", "Int", 1, "UPTR")

参数

OutputVar(输出变量)

用于存储指向新代码的行指针的变量名称,如果无法添加代码,将存储 0。

NewCode(新代码)

添加到当前运行脚本的新代码。

WaitExecute(等待执行,可选)

0 = 添加代码但不执行。
1 = 添加代码,执行并等待返回。
2 = 添加代码,立即执行并返回(不要等待代码结束执行)。

相关

ahkFindFunc, addFile, ahkFindLabel, ahkassign

示例

dllpath:=A_AhkDir "\AutoHotkey.dll"
DllCall("LoadLibrary","Str",dllpath) ; 加载 AutoHotkey 模块。
DllCall(dllpath "\ahktextdll","Str","","Str","","Cdecl") ; 启动新的空线程。
DllCall(dllpath "\addScript","Str","MsgBox Hello World!","Int",1,"CDecl") ; 添加并执行代码

; 使用内置 AutoHotkey.dll 的同等示例
dll:=AhkThread()
dll.addScript["MsgBox Hello World!",1]

; 在当前线程中添加并执行脚本
addScript("MsgBox Test",1)