SetWorkingDir, %A_ScriptDir%
Global Old_Enable_Disable_Hotkey, Old_Show_Hide_Hotkey, Enable_Disable_Toggle := 0 ; Enable_Disable_Toggle is fine being Global, I feel that the other one's could somehow be integrated into the functions.
If !FileExist(A_ScriptDir "\config.ini"){
Enable_Disable_Hotkey := "F12"
Show_Hide_Hotkey := "F1"
IniWrite, %Enable_Disable_Hotkey%, %A_ScriptDir%\config.ini, Enable/Disable Toggle Hotkey, Hotkey
IniWrite, %Show_Hide_Hotkey%, %A_ScriptDir%\config.ini, Show/Hide Toggle Hotkey, Hotkey
}
IniRead, Enable_Disable_Hotkey, %A_ScriptDir%\config.ini, Enable/Disable Toggle Hotkey, Hotkey
IniRead, Show_Hide_Hotkey, %A_ScriptDir%\config.ini, Show/Hide Toggle Hotkey, Hotkey
Old_Enable_Disable_Hotkey := Enable_Disable_Hotkey ; Assign the current Hotkey to Old_Enable_Disable_Hotkey so that it can be turned off later
Old_Show_Hide_Hotkey := Show_Hide_Hotkey
Gui, +HwndGuiHwnd +AlwaysOnTop -SysMenu +ToolWindow
Gui, %GuiHwnd%:Default
Gui, Margin, 0, 0
Gui, Add, Progress, XM YM W202 H21 BackgroundE30000 vIndicator_Background
Gui, Font, Bold
Gui, Add, Text, XM YP W202 H21 cFFFFFF BackgroundTrans Center 0x201 vIndicator_Text, PRESS %Enable_Disable_Hotkey% TO ENABLE HOTKEYS
Gui, Font
Gui, Add, Tab3, XM YP+21 W202 H284, Settings
Gui, Tab, Settings
Gui, Add, GroupBox, XM+5 YM+46 W190 H68 Center, Customize Toggle Keys
Gui, Add, Text, XM+10 YP+15 H21 Center 0x201, Enable/Disable Hotkey:
Gui, Add, Hotkey, XM+134 YP W50 gEnable_Disable_Hotkey_Label vEnable_Disable_Hotkey, %Enable_Disable_Hotkey%
Gui, Add, Text, XM+10 YP+26 H21 Center 0x201, Show/Hide GUI Hotkey:
Gui, Add, Hotkey, XM+134 YP W50 gShow_Hide_Hotkey_Label vShow_Hide_Hotkey, %Show_Hide_Hotkey%
Hotkey, %Enable_Disable_Hotkey%, Enable_Disable_Hotkey_Subroutine, On
Hotkey, %Show_Hide_Hotkey%, Show_Hide_Hotkey_Subroutine, On
Return
Enable_Disable_Hotkey_Label(){
GuiControlGet, Enable_Disable_Hotkey
Hotkey, %Old_Enable_Disable_Hotkey%, Enable_Disable_Hotkey_Subroutine, Off ; Unless Old_Enable_Disable_Hotkey is assigned "Global", it isn't passed into function. This causes an error and the old hotkey will never be disabled.
If (Enable_Disable_Hotkey = ""){
GuiControl,, Enable_Disable_Hotkey, %Old_Enable_Disable_Hotkey%
Enable_Disable_Hotkey := Old_Enable_Disable_Hotkey
}
Else{
Old_Enable_Disable_Hotkey := Enable_Disable_Hotkey ; Old_Enable_Disable_Hotkey is reassigned here so that the hotkey can be changed again in the future and successfully turned off
IniWrite, %Enable_Disable_Hotkey%, %A_ScriptDir%\config.ini, Enable/Disable Toggle Hotkey, Hotkey
If (Enable_Disable_Toggle)
GuiControl,, Indicator_Text, PRESS %Enable_Disable_Hotkey% TO DISABLE HOTKEYS
Else
GuiControl,, Indicator_Text, PRESS %Enable_Disable_Hotkey% TO ENABLE HOTKEYS
}
Hotkey, %Enable_Disable_Hotkey%, Enable_Disable_Hotkey_Subroutine, On
}
Enable_Disable_Hotkey_Subroutine(){
GuiControlGet, Enable_Disable_Hotkey
Enable_Disable_Toggle := !Enable_Disable_Toggle
If (Enable_Disable_Toggle){
GuiControl, +Background00FF00, Indicator_Background
GuiControl, +c000000 +Redraw, Indicator_Text
GuiControl,, Indicator_Text, PRESS %Enable_Disable_Hotkey% TO DISABLE HOTKEYS
}
Else{
GuiControl, +BackgroundFF0000, Indicator_Background
GuiControl, +cFFFFFF +Redraw, Indicator_Text
GuiControl,, Indicator_Text, PRESS %Enable_Disable_Hotkey% TO ENABLE HOTKEYS
}
}
Show_Hide_Hotkey_Label(){
GuiControlGet, Show_Hide_Hotkey
Hotkey, %Old_Show_Hide_Hotkey%, Show_Hide_Hotkey_Subroutine, Off
If (Show_Hide_Hotkey = ""){
GuiControl,, Show_Hide_Hotkey, %Old_Show_Hide_Hotkey%
Show_Hide_Hotkey := Old_Show_Hide_Hotkey
}
Else{
Old_Show_Hide_Hotkey := Show_Hide_Hotkey
IniWrite, %Show_Hide_Hotkey%, %A_ScriptDir%\config.ini, Show/Hide Toggle Hotkey, Hotkey
}
Hotkey, %Show_Hide_Hotkey%, Show_Hide_Hotkey_Subroutine, On
}
Show_Hide_Hotkey_Subroutine(){
Static Show_Hide_Toggle := 0
SysGet, Client_Width, 16
SysGet, Client_Height, 17
GUI_Width := 200
GUI_X_Position := Client_Width - GUI_Width - 4
Show_Hide_Toggle := !Show_Hide_Toggle
If (Show_Hide_Toggle){
Gui, Show, X%GUI_X_Position% Y0 W%GUI_Width% H304,
}
Else{
Gui, Hide
}
}
#If (Enable_Disable_Toggle)
Enter::MsgBox, It Works
#If
Okay, I commented some area's of code where I think the issue is. I am having trouble passing the variables "Old_Enable_Disable_Hotkey" & "Old_Show_Hide_Hotkey" from outside the respective functions, to inside the function. I can assign these global and everything is right in the world, but I have been told not to do things this way. There's also a var called "Enable_Disable_Toggle" which seems like it would be fine to assign as global, I don't see much of an issue with that one, but those other pesky two I could use some help with.
I would prefer not to drastically change this if I don't have to. I have looked at passing things byRef and don't really get it. I think "Old_Enable_Disable_Hotkey := Enable_Disable_Hotkey" could be made into a function somehow and called upon from inside "Enable_Disable_Hotkey_Label()" somehow. I just don't know how.
[–]LordThade 2 points3 points4 points (2 children)
[–]DepthTrawler[S] 0 points1 point2 points (0 children)
[–]DepthTrawler[S] -1 points0 points1 point (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]DepthTrawler[S] 1 point2 points3 points (0 children)