I am having trouble to stop a Toggle loop subroutine after the hotkey is set to !toggle.
The !toggle subroutine would intercept the toggle loop in the middle of its execution.
It would swap toggle states because there is such if¨statement inside the loop.
the only way I found to fix it was to insert ¨if¨ breaks before each line of the loop, but I´m certain there is another way to do it, if someone could help me please.
I recoded it without the toggles and its more elegant, but I still would like to get the toggle version working because I have another hotkey I use that has toggles and loops, funny is that I didn´t have any problems using that one.
Also my both these hotkeys block ¨t¨ after the hotkey gets started and I have to close the script to get ¨t¨ working again. It was working fine before
If I couls also get an opinion if I´m using too many returns it would be appreciated.
here´s my code:
Code: Select all
{
#IfWinActive Path of Exile
SetBatchLines, 20ms
SetDefaultMouseSpeed, 1
SetKeyDelay, 50, 50
SetMouseDelay, 50
CoordMode, Mouse
SetWorkingDir c:\Users\FX-8120\My Documents\My Games\Path of Exile\Screenshots
#MaxThreadsperHotkey 2
#MaxThreads 2
{
t & XBUTTON2::
ttoggle := !ttoggle
BlockInput MouseMove
MouseGetPos, Xpos, Ypos
GetKeyState, LButtonstate, LButton
if LButtonstate = D
Mouseclick, left, , , , , U
If tToggle
{
MouseMove, 1660, 1025 ; t
MouseClick, left, 1660, 1025 ; t
ImageSearch, FrostWallX, FrostWallY, 1412, 480, 1604, 933, *10 FrostWallL3.png
if errorlevel = 1
ImageSearch, FrostWallX, FrostWallY, 1412, 480, 1604, 933, *10 FrostWallR4.png
if errorlevel = 0
{
MouseMove, FrostWallX, FrostWallY
MouseClick, left,FrostWallX, FrostWallY
MouseMove, Xpos, Ypos
Send, {t}
if LButtonstate = D
Mouseclick, left, , , , , D
BlockInput MouseMoveOff
Loop
{
If not tToggle
Break
Sleep, 2000
If not tToggle
Break
ImageSearch, , , 1400, 1015, 1680, 1075, *10 FrostWall-T.png
If ErrorLevel = 1
{
If not tToggle
Break
ttoggle := !ttoggle
If not tToggle
Break
Exit
}
}
}
if ErrorLevel = 1
{
MsgBox, 2, FrostWall, FrostWall could not be found on the screen., 0.2
MouseMove, Xpos, Ypos
if LButtonstate = D
Mouseclick, left, , , , , D
BlockInput MouseMoveOff
}
Return
}
If not tToggle
{
MouseMove, 1660, 1025 ; t
MouseClick, left, 1660, 1025 ; t
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetR2.png
if ErrorLevel = 1
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetL1.png
if ErrorLevel = 1
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetM1.png
if ErrorLevel = 0
{
MouseMove, FeetX, FeetY
MouseClick, left, FeetX, FeetY
}
if ErrorLevel = 1
MsgBox, 2, Feet, Feet could not be found on the screen., 0.2
MouseMove, Xpos, Ypos
if LButtonstate = D
Mouseclick, left, , , , , D
BlockInput MouseMoveOff
Return
}
Return
}
{
XBUTTON1 & t::
BlockInput MouseMove
MouseGetPos, Xpos, Ypos
GetKeyState, LButtonstate, LButton
if LButtonstate = D
Mouseclick, left, , , , , U
ImageSearch, , , 1400, 1015, 1680, 1075, *10 FrostWall-T.png
If ErrorLevel = 1
{
MouseClick, left, 1660, 1025 ; t
ImageSearch, FrostWallX, FrostWallY, 1412, 480, 1604, 933, *10 FrostWallL3.png
if errorlevel = 1
ImageSearch, FrostWallX, FrostWallY, 1412, 480, 1604, 933, *10 FrostWallR4.png
if errorlevel = 0
{
MouseClick, left,FrostWallX, FrostWallY
MouseMove, Xpos, Ypos
Send, {t}
}
if ErrorLevel = 1
{
MsgBox, 2, FrostWall, FrostWall could not be found on the menu., 0.2
MouseMove, Xpos, Ypos
}
if LButtonstate = D
Mouseclick, left, , , , , D
BlockInput MouseMoveOff
Return
}
If ErrorLevel = 0
{
MouseClick, left, 1660, 1025 ; t
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetR2.png
if ErrorLevel = 1
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetL1.png
if ErrorLevel = 1
ImageSearch, FeetX, FeetY, 1412, 480, 1604, 933, *100 FeetM1.png
if ErrorLevel = 0
{
MouseClick, left, FeetX, FeetY
}
if ErrorLevel = 1
MsgBox, 2, Feet, Feet could not be found on the screen., 0.2
MouseMove, Xpos, Ypos
if LButtonstate = D
Mouseclick, left, , , , , D
BlockInput MouseMoveOff
Return
}
}
Return
}
Please help, I´m hopeless
Thanks