我知道我错过了一些明显的东西,但我无法弄清楚为什么这不起作用。为什么不在第一个msgbox中显示你好,我知道如果我取消注释#Warn它没有分配变量?这是ahk文件中唯一的东西。
#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
答案 0 :(得分:1)
ADPass
的分配永远不会被执行,因为它位于2个热键之间。您必须在开始热键之前(^!z
之前)将其放置在热键(!5
)中以确保它已被执行。
答案 1 :(得分:0)
我认为其他答案可能会有效,您需要在返回之前设置变量。返回意味着机器永远不会到达那行代码,试试这个。
#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