0

我知道我遗漏了一些明显的东西,但我不知道为什么这不起作用。为什么 hello 没有出现在我知道的第一个 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
4

2 回答 2

1

你的任务ADPass永远不会被执行,因为它在 2 个热键之间。您必须在开始热键之前放置它(before ^!z)或将其放置在热键中(!5)以确保它被执行。

于 2013-07-23T20:48:17.220 回答
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
于 2013-07-23T21:13:06.463 回答