基本上我有一个依赖于全局变量的代码,然后将它的值保存到局部变量中,以便记住它在更改后的状态。然而,由于某种原因它根本就没有通过......
问题是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 :(得分:0)
所以我玩了它,我把PrevSlot变成了一个全局变量并删除了变量周围的%。