2013-07-23 35 views
0

我知道我錯過了明顯的東西,但我不明白爲什麼這不起作用。爲什麼你不會在第一個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 

回答

1

您的任務ADPass從未得到執行,因爲它在2個熱鍵之間。您必須在開始使用熱鍵之前(在^!z之前)將其放入熱鍵(!5)以確保其執行。

+0

謝謝,我一定是錯過了手冊中! –

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