请在AutoHotkey中执行以下脚本:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Persistent
Gosub, Mylabel
Return
MsgBox, It worked!
MyLabel:
Sleep, 1000
Return
我希望它可以调用MyLabel
,即等待1秒,然后弹出消息框。
但事实并非如此。
我在Gosub
运作中缺少什么?
答案 0 :(得分:1)
return
电话后面的行gosub
。
取出它,它会停止剧本。
像这样:
(1) Gosub, Mylabel
; Return
(2) MsgBox, It worked!
(3) MyLabel:
(4) Sleep, 1000
(5) Return
基本上,在Gosub
行之后,启动了 Mylabel 背后的代码。
一旦达到return
,它就会跳回并继续Gosub
之后的行。
这里的执行顺序是(1),跳转到标签(3),运行命令(4),运行return(5)因为先前发出了gosub,所以跳转到(1)之后的行,运行(2)并且你看到了消息。然后代码继续再次传递标签(3),再次运行(4),这次返回(5)完全停止脚本。