Autohotkey 导致变量未赋值的热键?
我知道我遗漏了一些明显的东西,但我不明白为什么这不起作用。为什么hello没有出现在我知道的第一个msgbox中,它说如果我取消注释#Warn,变量就没有赋值?这是ahk文件中唯一的内容Autohotkey 导致变量未赋值的热键?,autohotkey,Autohotkey,我知道我遗漏了一些明显的东西,但我不明白为什么这不起作用。为什么hello没有出现在我知道的第一个msgbox中,它说如果我取消注释#Warn,变量就没有赋值?这是ahk文件中唯一的内容 #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
ADPass = hello
!5::
MsgBox, %ADPass%
Msgbox, test
return
您的
ADPass
分配永远不会执行,因为它位于两个热键之间。您必须在开始热键之前放置它(在^!z之前)或将它放置在热键中(!5
)以确保它被执行。我认为另一个答案可能会起作用,您需要在返回之前设置变量。返回意味着机器永远不会到达该代码行,请尝试此操作
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
ADPass = hello; this doesn't have to stay here, just make sure it's before the return.
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
MsgBox, %ADPass%
Msgbox, test
return
或
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
goto set
point:
MsgBox, %ADPass%
Msgbox, test
return
set:
ADPass = hello
goto point
Return