2016-09-14 3 views
0

В принципе, у меня есть код, который полагается на глобальную переменную, а затем сохраняет его значение в локальную переменную, чтобы помнить, что она использовала после ее изменения. Однако это просто не проходит через по какой-то причине ...Переменные, не проходящие через AHK

Проблема заключается в том, что PrevSlot возвращает пустой и не сохраняет значение CurrentSlot в

CurrentSlot := 3 

NumpadDot:: 
PrevSlot := %CurrentSlot% 
    if (CurrentSlot != 0) { 
     PrevSlot := %CurrentSlot% 
     CurrentSlot := 0 
     CurrentSlotName := "0_QuickLaunchMenu.ahk" 
     ;MsgBox, , Title, "Quick Launch Menu", 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, "QuickLaunch.ahk" 
      { 
       Run, % A_WorkingDir "\QuickLaunch.ahk" 
      } 

     if not GuiActive 
     { 
      displayGui(500) 
     } else { 
      Gui, Destroy 
      GuiActive := 0 
      displayGui(0) 
     } 
    } else { 
     CurrentSlot := %PrevSlot% 
     CurrentSlotName := FileList[PrevSlot] 
     ;MsgBox, , Title, "Quick Launch Menu", 1 

     IfWinExist, "QuickLaunch.ahk" 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[PrevSlot] 
      { 
       Run, % A_WorkingDir "\NumbpadLayouts\" FileList[PrevSlot] 
      } 

     if not GuiActive 
     { 
      displayGui(500) 
     } else { 
      Gui, Destroy 
      GuiActive := 0 
      displayGui(0) 
     } 
    } 
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. 
DetectHiddenWindows, On 
SetTitleMatchMode, 2 

CurrentSlot := 2 
CurrentSlotName := "Media" 
FileList := [] 
GuiActive := 0 

Loop, Files, %A_WorkingDir%\NumbpadLayouts\*.ahk 
    FileList.Insert(A_LoopFileName) 

; Iterate from 1 to the number of items: 
;Loop % FileList.MaxIndex() 
; MsgBox % FileList[A_Index] 

; Enumerate the array's contents: 
;For index, value in FileList 
; MsgBox % "Script " index " is: '" value "'" 
;return 

IfWinNotExist, FileList[CurrentSlot] 
{ 
    Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
} 

;============================== [ Page Controls ] ============================== 
NumpadMult:: 
;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 
displayGui(0) 
return 

NumpadDiv UP:: 
    if (CurrentSlot > 1) { 
     PrevSlot := %CurrentSlot% 
     CurrentSlot -= 1 
     CurrentSlotName := FileList[CurrentSlot] 
     ;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[CurrentSlot] 
     { 
      Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
     } 
    } else { 
     PrevSlot := %CurrentSlot% 
     CurrentSlot := FileList.MaxIndex() 
     CurrentSlotName := FileList[CurrentSlot] 
     ;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[CurrentSlot] 
     { 
      Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
     } 
    } 
    if not GuiActive 
    { 
     displayGui(500) 
    } else { 
     Gui, Destroy 
     GuiActive := 0 
     displayGui(0) 
    } 
return 

NumpadSub UP:: 
    if (CurrentSlot < FileList.MaxIndex()) { 
     PrevSlot := %CurrentSlot% 
     CurrentSlot += 1 
     CurrentSlotName := FileList[CurrentSlot] 
     ;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[CurrentSlot] 
     { 
      Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
     } 
    } else { 
     PrevSlot := %CurrentSlot% 
     CurrentSlot := 1 
     CurrentSlotName := FileList[CurrentSlot] 
     ;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[CurrentSlot] 
     { 
      Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
     } 
    } 
    if not GuiActive 
    { 
     displayGui(500) 
    } else { 
     Gui, Destroy 
     GuiActive := 0 
     displayGui(0) 
    } 
return 

;============================== [ Quick Launch ] ============================== 
NumpadDot UP:: 
PrevSlot := CurrentSlot 
    if (CurrentSlot != 0) { 
     ;PrevSlot := %CurrentSlot% 
     CurrentSlot := 0 
     CurrentSlotName := "0_QuickLaunchMenu.ahk" 
     ;MsgBox, , Title, "Quick Launch Menu", 1 

     IfWinExist, FileList[PrevSlot] 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, "QuickLaunch.ahk" 
      { 
       Run, % A_WorkingDir "\QuickLaunch.ahk" 
      } 

     if not GuiActive 
     { 
      displayGui(500) 
     } else { 
      Gui, Destroy 
      GuiActive := 0 
      displayGui(0) 
     } 
    } else { 
     CurrentSlot := %PrevSlot% 
     CurrentSlotName := FileList[PrevSlot] 
     ;MsgBox, , Title, "Quick Launch Menu", 1 

     IfWinExist, "QuickLaunch.ahk" 
     { 
      WinClose ; use the window found above 
     } 

     IfWinNotExist, FileList[PrevSlot] 
      { 
       Run, % A_WorkingDir "\NumbpadLayouts\" FileList[PrevSlot] 
      } 

     if not GuiActive 
     { 
      displayGui(500) 
     } else { 
      Gui, Destroy 
      GuiActive := 0 
      displayGui(0) 
     } 
    } 
return 

QuickLaunchFunction(slot) 
{ 
    global 

    if (CurrentSlot = 0) { 
     if (slot <= FileList.MaxIndex()) { 
      ;local PrevSlot := %CurrentSlot% 
      CurrentSlot := slot 
      CurrentSlotName := FileList[CurrentSlot] 
      ;MsgBox, , Title, Current Slot: %CurrentSlotName%, 1 

      IfWinExist, FileList[local PrevSlot] 
      { 
       WinClose ; use the window found above 
      } 

      IfWinNotExist, FileList[CurrentSlot] 
      { 
       Run, % A_WorkingDir "\NumbpadLayouts\" FileList[CurrentSlot] 
      } 
      if not GuiActive 
      { 
       displayGui(500) 
      } else { 
       Gui, Destroy 
       GuiActive := 0 
       displayGui(0) 
      } 
     } else { 
      MsgBox, , Title, %slot% doesn't exsist, 1 
     } 
    } 
} 
;============================== [ Numberpad QuickLaunch Keys ] ============================== 
Numpad0:: 
QuickLaunchFunction(0) 
return 
Numpad1:: 
QuickLaunchFunction(1) 
return 
Numpad2:: 
QuickLaunchFunction(2) 
return 
Numpad3:: 
QuickLaunchFunction(3) 
return 
Numpad4:: 
QuickLaunchFunction(4) 
return 
Numpad5:: 
QuickLaunchFunction(5) 
return 
Numpad6:: 
QuickLaunchFunction(6) 
return 
Numpad7:: 
QuickLaunchFunction(7) 
return 
Numpad8:: 
QuickLaunchFunction(8) 
return 
Numpad9:: 
QuickLaunchFunction(9) 
return 

;NumpadEnter:: 
;NumpadAdd:: 

;============================== [ Functions ] ============================== 
displayGui(length) 
{ 
    global 
    if not GuiActive 
    { 
     GuiActive := 1 ;Sets the GuiActive status to active (Aka the gui is currently being displayed) 

     CustomColor = 000000 ;Can be any RGB color (it will be made transparent below). 
     Gui +LastFound +AlwaysOnTop -Caption +ToolWindow ;+ToolWindow avoids a taskbar button and an alt-tab menu item. 

     ;Gui, Add, Picture, x40 y40 w80 h80 , %Numpad7Img% ;Adds Gui Image 
     Gui, Add, Text, x10 y5 w220 h25 , %CurrentSlotName% 


     ;Gui, Color, %CustomColor% 
     ;WinSet, TransColor, %CustomColor% 

     Gui, Show, x1740 y1015 h25 w220 NoActivate ; NoActivate avoids deactivating the currently active window. 

     if (length > 0) 
     { 
      sleep, %length% 
      Gui, Destroy 
      GuiActive := 0 ;Sets the GuiActive status to inactive (Aka the gui is currently not being displayed) 
     } 
    } else { 
     Gui, Destroy 
     GuiActive := 0 ;Sets the GuiActive status to inactive (Aka the gui is currently not being displayed) 
    } 
} 
+0

'PrevSlot: =% CurrentSlot%' получает значение переменной, имя которой находится в 'CurrentSlot'. С ': =' вам не нужны знаки процента. См. Также [autohotkey назначает текстовое выражение переменной] (https://stackoverflow.com/a/17498698) – wOxxOm

+0

Здравствуйте, снова wOxxOm! Я пробовал без%, и он все еще не проходит. Я даю вам весь код, чтобы дать вам лучшую перспективу, и, возможно, что-то еще играет, но я просто не понимаю. Например, у меня есть другие горячие клавиши, которые имеют очень похожие функции, и переменные проходят через них, поэтому я действительно не уверен. – CTOverton

ответ

0

Так что я играл с ним, и я сделал PrevSlot глобальной переменной и удалил% вокруг переменной.

Смежные вопросы