我有一个问题我无法解决AHK问题。我的代码:
begin()
begin() {
Global Input
Gui, Add, Edit, vInput gInputChanged
}
InputChanged() {
MsgBox, Your input is %Input%
}
很简单,嗯?但是,当触发InputChanged()
时,变量Input
永远不会正确(它始终为空)。
答案 0 :(得分:0)
请参阅Function Variables and Scope
示例:
Input := "Hello" ; Our Variable Defined outside of our Function
begin() ; Call the function passing no Variables
begin() {
Global Input
MsgBox, Global! Input = %Input%
InputChangedLocally(Input) ; Pass the Input variable which is 'Hello'
}
InputChangedLocally(Input) {
Input .= " World!" ; Change Local variable
MsgBox, Changed Locally %Input%
OnlyGlobalInput()
}
OnlyGlobalInput() {
Global Input
; Notice it is not 'Hello World!' even though we changed it above!
MsgBox, Global! Input = %Input%
InputNotPassedOrGlobal()
}
InputNotPassedOrGlobal() {
MsgBox, Your input is %Input% ; Blank as we never accessed any thing!
}