Can't figure out how to leave loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Can't figure out how to leave loop

07 May 2018, 16:26

So I've got the following function working great. It switches the scroll lock light on/off as my mic is muted/unmuted.

Code: Select all

mutemic()
{
SoundSet, +1, MASTER, mute,11
SoundGet, master_mute, MASTER, mute, 11
Sleep, 100
if master_mute = on
  KeyboardLED(1,"on")
else
  KeyboardLED(0,"off")
}
Return
I'd like to gussy it up a bit and make the scroll light blink, but I'm not sure how to get out of this loop.
It starts the way I want it to, it mutes the mic and starts the light blinking, but because it's now stuck in the loop it won't look for the off command.

Code: Select all

mutemic()
{
SoundSet, +1, MASTER, mute,11
SoundGet, master_mute, MASTER, mute, 11
Sleep, 100
if master_mute = on
{
    Loop
    {
      KeyboardLED(1,"on") ;
      Sleep, 500
      KeyboardLED(1,"off")
      Sleep, 500
    }
}
else
  KeyboardLED(0,"off")
}
Return
I'm hoping the solution is overly complicated so I don't feel too dumb.

Thanks in advance,
neverlevel
Posts: 60
Joined: 13 Apr 2016, 22:02

Re: Can't figure out how to leave loop

07 May 2018, 16:33

F2::reload?

probably not what you want.

could always use goto and add a sub up near the top to force the check

Code: Select all

mutemic()
{
SoundSet, +1, MASTER, mute,11
SoundGet, master_mute, MASTER, mute, 11
Sleep, 100
Recheck:
if master_mute = on
{
      KeyboardLED(1,"on") ;
      Sleep, 500
      KeyboardLED(1,"off")
      Sleep, 500
      Goto, recheck
    }
else
  KeyboardLED(0,"off")
}
Return


tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Re: Can't figure out how to leave loop

07 May 2018, 16:46

Not a bad idea, thank you. I tried it out, and am still stuck in the loop. I'll try removing the loop maybe?.
eelrod
Posts: 65
Joined: 10 Apr 2018, 11:17

Re: Can't figure out how to leave loop

07 May 2018, 16:50

If you wish for it to blink for the entire duration that the mic is muted, I would suggest using SetTimer instead of the Loop.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Can't figure out how to leave loop

07 May 2018, 16:51

You can exit loops using break. However, you'd likely want to use while instead, or alternatively SetTimer.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Re: Can't figure out how to leave loop

07 May 2018, 16:51

eelrod wrote:If you wish for it to blink for the entire duration that the mic is muted, I would suggest using SetTimer instead of the Loop.
Good point, I left that out of the original post. Yes, I do want it to blink for as long as it's muted.
I'll look into how to use SetTimer. Thank you.
tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Re: Can't figure out how to leave loop

07 May 2018, 17:35

Code: Select all

mutemic()
{
SoundSet, +1, MASTER, mute,11
SoundGet, master_mute, MASTER, mute, 11
Sleep, 100

SetTimer, blink, 250

blink:
{
  if master_mute = on
  {
    KeyboardLED(1,"on") ;
    Sleep, 500
    KeyboardLED(1,"off")
    Sleep, 500
    return
  }
else
  KeyboardLED(0,"off")
}
return
}
Not sure if I'm using SetTimer right. It blinks the light 3 times for some reason when muted, then stops blinking. The microphone is still muted.
tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Re: Can't figure out how to leave loop

09 May 2018, 18:44

Still not sure how to properly implement the SetTimer in this situation.
Any ideas?
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Can't figure out how to leave loop

10 May 2018, 16:13

Your blink label is within a function, which is likely improper. Is master_mute defined somewhere?
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
tgoVIPER
Posts: 14
Joined: 22 Apr 2018, 10:28

Re: Can't figure out how to leave loop

25 May 2018, 18:15

SirRFI wrote:Your blink label is within a function, which is likely improper. Is master_mute defined somewhere?
master_mute is defined in the SoundGet call.

I still haven't been able to figure it out.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 262 guests