Curly braces in Autohotkey "Send" command conflicting with hotkey braces

0

It's pretty hard to explain without showing the code first, so here goes:

This is the code:

#l::
{
SoundGet, mutestate, , MUTE
if mutestate = Off
    Send {Volume_Mute}
Sleep 200
DllCall("LockWorkStation")
Sleep 200
SendMessage,0x112,0xF170,2,,Program Manager
Return
}

And this is the log output:

002: {
003: SoundGet,mutestate,,MUTE
004: if mutestate = Off
005: Sleep,200 (0.20)
006: DllCall("LockWorkStation")  
007: Sleep,200 (0.20)
008: SendMessage,0x112,0xF170,2,,Program Manager
009: Return (16.63)

Now to the actual "problem".

There is one part of the actual code that doesn't show up in the log (but still executes), which is the Send {Volume_Mute}. I've tested that it still runs by setting volume to maximum, then triggering the hotkey. It locks the computer, then mutes it, which is exactly what it's supposed to do.

I'm just wondering why doesn't it show up in the log at all. My only guess would be that the curly braces is probably causing the "problem".

#l::
{                                              << This brace
SoundGet, mutestate, , MUTE
if mutestate = Off
    Send {Volume_Mute}                         << The 2 braces here
Sleep 200
DllCall("LockWorkStation")
Sleep 200
SendMessage,0x112,0xF170,2,,Program Manager
Return
}                                              << And this brace

I'm not really sure if this is what's causing the problem, but I'd really like to know what exactly is the cause.

SerinEleven

Posted 2013-12-26T09:53:06.227

Reputation: 15

Answers

0

After Windows XP, SoundGet is not the best way to get the mute state. I recommend checking out the Vista Audio Library which I believe is currently the best method.

Simply save the file to your script's directory and include the it by using #Include like this:

#Include VA.ahk

And here is the equivalent of your first 3 lines of code:

if ! VA_GetMasterMute() 
    VA_SetMasterMute(true)

Elliot DeNolf

Posted 2013-12-26T09:53:06.227

Reputation: 843

The new code now shows up in the log and does the muting. Just wondering why the former code doesn't show up in the log though. Some minor incompatibilities? – SerinEleven – 2013-12-27T02:41:53.303

Judging by the documentation SoundGet retrieves the mute state of the script only, not of windows (mastermute in this case). Mutestate was not the value that was expected, which I verified using a msgbox. – Elliot DeNolf – 2013-12-27T13:41:54.363