Mute/unmute Internet Explorer via Windows Volume Mixer? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Mute/unmute Internet Explorer via Windows Volume Mixer?

15 Oct 2017, 22:05

I'd like to be able to selectively mute Internet Explorer. The use case is streaming background audio in IE, and when I want to listen to something else (say, audio/video I pulled up in Chrome), I want to mute IE.

Unlike Chrome or Firefox, IE doesn't have any extensions that provide keyboard shortcut access to mute/unmute the app. So it would seem the best option is using the Windows Volume Mixer, which looks like this (it will show System Sounds along with whichever apps are playing audio):
Image

Since IE won't always be the third item, I can't simply hardcode tabs that bring focus to IE's volume control. WindowSpy shows something that may be useful - if I hover over the mute/unmute button (the speaker icon) at the bottom of the volume slider for IE, WindowSpy shows:

ClassNN: ToolbarWindow326 (the particular number changes, so I cannot anchor on that)
Text: Mute for Internet Explorer

Is there a way to navigate to this particular control using the text for the control? If so, I could navigate to the mute/unmute for IE and send a left click.

If not, I suppose I could do an image search for the IE icon, then mouse move down a fixed distance to where the mute/unmute control is.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Mute/unmute Internet Explorer via Windows Volume Mixer?

15 Oct 2017, 22:32

This is a throwback to years ago. First, here's raw code I used for increasing or decreasing the volume of Chrome by 10%.

Actually, First First, if you have never used the Window Spy, you should try it out and explore the Volume Mixer. Window Spy can be accessed by right-clicking the tray icon (by the system clock) of a running script.

Code: Select all

#IfWinExist, YouTube - Google Chrome
!u::
SetFormat, FloatFast, 0
Run, sndvol.exe,,Minimize ; sndvol.exe is the Volume Mixer program. Hide makes it run in the background. ; I think my script had `DetectHiddenWindows, On` in it somewhere
;ControlGet, var, hwnd,,,YouTube - Google Chrome
WinWait, ahk_exe SndVol.exe
WinGet, listVar, ControlList, ahk_exe SndVol.exe
Loop, parse, listVar, `n, `r
{
ControlGetText, text, %A_LoopField% ; each item in the list is checked for its text
If text contains YouTube - Google Chrome
{
	controlOfInterest:=A_LoopField ; this will store a value of Static_ where _ is some number.
    Break
}
}
StringTrimLeft, staticNumber, controlOfInterest, 6
staticNumber++ ; add 1 to this number
suffix:=staticNumber/3 ; find out how many times this can be divided by 3, stored in variable suffix
suffix+=320 ; add 320 to suffix
ControlSend, msctls_trackbar%suffix%, {up 10}, ahk_exe SndVol.exe
WinClose, ahk_exe SndVol.exe
return

!d::
SetFormat, FloatFast, 0
Run, sndvol.exe,,Minimize ; sndvol.exe is the Volume Mixer program. Hide makes it run in the background.
;ControlGet, var, hwnd,,,YouTube - Google Chrome
WinWait, ahk_exe SndVol.exe
WinGet, listVar, ControlList, ahk_exe SndVol.exe
Loop, parse, listVar, `n, `r
{
ControlGetText, text, %A_LoopField% ; each item in the list is checked for its text
If text contains YouTube - Google Chrome
{
	controlOfInterest:=A_LoopField ; this will store a value of Static_ where _ is some number.
    Break
}
}
StringTrimLeft, staticNumber, controlOfInterest, 6
staticNumber++ ; add 1 to this number
suffix:=staticNumber/3 ; find out how many times this can be divided by 3, stored in variable suffix
suffix+=320 ; add 320 to suffix
ControlSend, msctls_trackbar%suffix%, {down 10}, ahk_exe SndVol.exe
WinClose, ahk_exe SndVol.exe
return
This is a MsgBox I captured when I was developing this code. I think this is what I got when I used MsgBox %listVar% from the WinGet, listVar, ControlList, ahk_exe SndVol.exe.

Code: Select all

---------------------------
&Test Script.ahk
---------------------------
Volume Flood1
TileListView1
TileSled Window1
#327701
Static1
ToolbarWindow321
Static2
Static3
msctls_trackbar321
ToolbarWindow322
#327702
Static4
ToolbarWindow323
Static5
Static6
msctls_trackbar322
ToolbarWindow324
#327703
Static7
ToolbarWindow325
Static8
Static9
msctls_trackbar323
ToolbarWindow326
#327704
Static10
ToolbarWindow327
Static11
Static12
msctls_trackbar324
ToolbarWindow328
#327705
Static13
ToolbarWindow329
Static14
Static15
msctls_trackbar325
ToolbarWindow3210
#327706
Static16
ToolbarWindow3211
Static17
Static18
msctls_trackbar326
ToolbarWindow3212
#327707
Static19
ToolbarWindow3213
Static20
Static21
msctls_trackbar327
ToolbarWindow3214
Static22
ToolbarWindow3215
Static23
ToolbarWindow3216
Static24
msctls_trackbar328
ToolbarWindow3217
SPD_GroupBox1
SPD_GroupBox2
---------------------------
OK   
---------------------------
What you see in the MsgBox is a pattern. The pattern I see is in this example, they kind of run in blocks:

Code: Select all

#327702 ; this is the second program in the Volume Mixer
Static4
ToolbarWindow323
Static5
Static6
msctls_trackbar322
ToolbarWindow324

#327703 ; this is the third program in the Volume Mixer
Static7
ToolbarWindow325
Static8
Static9
msctls_trackbar323
ToolbarWindow326
So my code manages to identify when Google Chrome was the nth item in a list; this text managed to correspond with the Static_ control, where _ was 3, 6, 9, etc. I could then do math to figure out what multiple of 3 the control; 12/3 = 4 for example. You would then add that number (4) to 320 to figure out what the corresponding name for msctls_trackbar___ is; msctls_trackbar324 today.

Now, I had to send up/down keys to the trackbar control to change the volume. You just want to mute. My Window Spy says the ToolbarWindow322, 324, 326, etc. are the mute buttons. You should use ControlClick on these, but using ControlSend and sending a {Space} may work. Anyhow, what's the math for identifying the ToolbarWindow322, 324, etc.? It would be 2/3rds of the static value. That is, when Static9 corresponds to the window you want, then you want ToolbarWindow326. So take the 9 from Static 9, multiply be 2/3, and you get 6. Add that to 320 for 326, and you get ToolbarWindow326.

Hope that helps. It's not perfectly clear, I know. Try to read the documentation links in the very first codebox to understand each command and try to understand what I'm doing. (I don't entirely recall what I was doing back then, but it worked ^^).
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Mute/unmute Internet Explorer via Windows Volume Mixer?  Topic is solved

16 Oct 2017, 00:26

To set the volume of a trackbar control you can use this:

Code: Select all

q::
SendMessage, 0x422,, 50, msctls_trackbar321, A ;TBM_SETPOSNOTIFY := 0x422
return
For Volume Mixer, it's counterintuitively: 100 for silent, 0 for maximum volume.

NirCmd can mute programs.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
redrum
Posts: 83
Joined: 25 Jan 2015, 22:57

Re: Mute/unmute Internet Explorer via Windows Volume Mixer?

16 Oct 2017, 14:38

Thanks to you both for the various options to accomplish this task.

I went with NirCmd since it's so simple.

For anyone who is looking to do the same/similar, just download nircmd and use code similar to this:

Code: Select all

IfWinExist, ahk_exe iexplore.exe
	RunWait, D:\Downloads\nircmd\nircmd.exe muteappvolume iexplore.exe 2
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Dobbythenerd1 and 337 guests