开发者

Autohotkey script for muting speakers for a certain number of seconds

I'm trying to use Autohotkey to create a script that will Mute the computer's speakers for a number of seconds. Thi开发者_如何学Cs is useful for watching television online -- when it comes to a commerical, it will give a message saying 'programming will resume in XX seconds'. If it says 30 seconds, then I would like to hit Windows-KeyPad3 to indicate to mute the speakers for 30 seconds, then automatically unmute.

My Main autohotkey.ahk script:

#Numpad1::RUN mute10.ahk
#Numpad2::RUN mute20.ahk
#Numpad3::RUN mute30.ahk
#Numpad4::RUN mute40.ahk
#Numpad5::RUN mute50.ahk
#Numpad6::RUN mute60.ahk
#Numpad7::RUN mute70.ahk
#Numpad8::RUN mute80.ahk
#Numpad9::RUN mute90.ahk

And my mute10.ahk script:

SoundSet, 1, , mute  
pause 10000
SoundSet, 0, , mute  

But for some reason the pause command doesn't seem to be right. There must be another correct command, but I can't seem to find it in the docs


Use sleep instead of pause:

sleep 10000


Horrible, why have a dozen scripts when one will do?

#Numpad1::
#Numpad2::
#Numpad3::
#Numpad4::
#Numpad5::
#Numpad6::
#Numpad7::
#Numpad8::
#Numpad9::
    ; extract the last character from the hotkey (the number) and multiply it by 10
    ; mute for that many seconds
    mute(substr(A_ThisHotkey, 0) * 10) 
return

mute(seconds)
{
    SoundSet, 1, , mute 
    sleep seconds * 1000
    SoundSet, 0, , mute
}


Note, per the AutoHotKey documentation, SoundSet does not work system-wide on Windows Vista and later. "Send {Volume_Mute}" to toggle mute is an alternative.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜