Simple: The script mutes the sound by sending {Volume_Mute}, then sleeps for the specified time, then sends {Volume_Mute} to unmute the sound.
All that works fine, but if I press the hotkey again, I need it to abandon the previous sleep timer and start again. (I might need to extend or change how long my laptop is muted for). I had hoped that #SingleInstance Force would do that, but it doesn't work.
What happens is that both instances seem to run concurrently, and then wait until the final sleep timer has completed, and then both instances issue the keystroke {Volume_Mute}.
So the sound is unmuted and immediately muted again.
How can I make this work correctly? Note - the final code will mute for up to 60 minutes, not just a few seconds.
Code: Select all
#SingleInstance Force
^m::
Gui, destroy
Gui, font,bold
Gui,Add,Text,,Mute volume for:
Gui, font
Gui, Add, Radio, altsubmit gSetMute vOption, 20 seconds
Gui, Add, Radio, altsubmit gSetMute, 30 seconds
Gui, Show
return
SetMute:
GuiClose:
GuiEscape:
Gui, Submit ; Save each control's contents to its associated variable.
SoundGet, master_mute,, Mute
if (master_mute = "Off")
Send {Volume_Mute}
if (Option = 1){
MsgBox, , Audio Volume, Muted for 20 seconds, 2
Sleep, 20000
}
if (Option = 2){
MsgBox, , Audio Volume, Muted for 30 seconds, 2
Sleep, 30000
}
SoundGet, master_mute,, Mute
if (master_mute = "On")
msgbox, unmute ;instead of "send {Volume_Mute}" to see whats happening
return