I searched a lot on the site but did not find how to do it. This is my current script:
MButton::
MouseGetPos, xpos, ypos
Sleep, 50
Click
Loop
{
Sleep 50
Send, {\ down}
Sleep 50
Send, {\ up}
}
Click %xpos%, %ypos%, 0
Return
I would like to end the loop by pressing the middle button of the mouse (MButton). I think is not a difficult task but cannot find it out, can you help thanks very much
EDIT so the code posted by @Jim U, and @user3419297 works very well! Code by GroggyOtter gives error when I run it. Code by Forivin seems to work in another way (explained below). Thank you so much to all of you!
EDIT 2 an even more easy code
MButton::
MouseGetPos, xpos, ypos
Sleep, 50
Click
Loop
{
Sleep 50
Send, {\ down}
Sleep 50
Send, {\ up}
If GetKeyState("MButton", "P") AND (A_TimeSinceThisHotkey > 300) ; When the MButton is pressed and after 300ms have elapsed(to prevent it from stopping direcly after triggering it.
Break
}
Click %xpos%, %ypos%, 0
Return