Page 1 of 1

MButton Up to toggle on off a loop script  Topic is solved

Posted: 25 Jan 2016, 10:44
by kilokore
Hi,

I'm trying to create a script where on MButton Up, I can toggle on or off a loop script, which will do various Send's and Sleep's.
I have tried writing this with the following:

Code: Select all

MButton UP:: Toggle := Toggle ? 0 : 1
#If Toggle
but no matter what i put after this, whether it be loop or a command, I cannot get another 'MButton Up' to toggle it off.

So ideally:
1. On MButton Up, loop starts (send a every 15 seconds)
2. On another MButton Up, loop ends, and the script is paused

Please help. Thanks,

Re: MButton Up to toggle on off a loop script

Posted: 25 Jan 2016, 16:27
by Shadowpheonix
Something in the code you have after the #If Toggle is interfering. Most likely your other code is holding down Shift or Ctrl or something. Try changing MButton Up:: to *MButton Up::. If that does not help, then please post the rest of your script.

Re: MButton Up to toggle on off a loop script

Posted: 25 Jan 2016, 21:13
by kilokore
Hi,
I've made changes to my script as follows:

Code: Select all

toggle = 0
Mbutton UP::
Toggle := !Toggle
While Toggle{

	Send q
	Sleep 15
	Send w
	Sleep 2000
}
return
basically the goal is to:
1. Press MButton and release, which will start the loop that:
2. sends q followed by w, wait 2 seconds and repeat until:
3. I press and release MButton again
4. Repeat 1 as needed

Right now the code works for 1 and 2, but won't stop after the second MButton press.
Any help on this would be greatly appreciated.

Thanks,

Re: MButton Up to toggle on off a loop script

Posted: 26 Jan 2016, 09:45
by Shadowpheonix
Ah. You need to add a line reading #MaxThreadsPerHotkey 2 to the top of your script.

Re: MButton Up to toggle on off a loop script

Posted: 26 Jan 2016, 13:37
by kilokore
Thanks! I think that might have done the trick.