Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Vista Audio Control Functions


  • Please log in to reply
182 replies to this topic
element
  • Members
  • 24 posts
  • Last active: Oct 20 2011 09:15 AM
  • Joined: 02 Apr 2010

After spending several hours researching it, wrapping various COM interfaces and experimenting I'm able to enumerate audio sessions and determine which app owns them, but not control their volume.

Thanks for looking into it. Seems like the only solution right now is to move the sliders in the Win mixer. I could do this in AHK with a mouse macro, but that's a bit cheesy. If someone knows how to send window messages to the Win7 audio mixer, please let me know.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
TBM_GETPOS and TBM_SETPOSNOTIFY seem to work.
SendMessage TBM_GETPOS:=0x400,,, msctls_trackbar321, Volume Mixer
v := ErrorLevel - 5  ; Note range is 0-100, but reversed.
SendMessage TBM_SETPOSNOTIFY:=0x422, 1, v, msctls_trackbar321, Volume Mixer
SoundPlay *-1
You may need to use WinGet List and possibly ControlGetPos/ControlGetText to determine which slider to move.

element
  • Members
  • 24 posts
  • Last active: Oct 20 2011 09:15 AM
  • Joined: 02 Apr 2010
Thanks for the message codes. I put together a function that takes the name of the app, the desired vol. level, and sets the relevant volume slider. Identifying the slider by app name is a bit hacky. It relies on the hor. distance from the text label control. This may need tweaking for your DPI/font settings, but it works for me.

SetTitleMatchMode 2
; Name of the app you want to control
appName = System Sounds
; Volume level you want
newVal = 50 ; 0-100

Run sndvol ; launch Win sound mixer
WinWait Volume Mixer
SetVal(appName, newVal)
WinClose Volume Mixer ; close the mixer

SetVal(appName, newVal) {
   ; the slider IDs seem to start at 321
   startIDX = 321
   ; the app slider is identified by hor. distance from its text label
   ; maxDiff below sets the maximum allowed distance
   ; On my system, with my DPI and fonts, the reported distance is 36
   maxDiff = 40

   ControlGetPos, refX, , , , % appName, Volume Mixer
   x = 1
   while ( x != "") {
      tbIDX := startIDX + A_Index - 1
      ControlGetPos, x, , , , msctls_trackbar%tbIDX%, Volume Mixer
      diff := Abs(x-refX)
      if (diff < maxDiff && diff != "")
      {
         ; msgbox diff: %diff% refX: %refX% tbIDX: %tbIDX% x: %x%
         ; SendMessage TBM_GETPOS:=0x400,,, msctls_trackbar%tbIDX%, Volume Mixer
         v := 100 - newVal  ; Note range is 0-100, but reversed.
         SendMessage TBM_SETPOSNOTIFY:=0x422, 1, v, msctls_trackbar%tbIDX%, Volume Mixer
         break
      }
   }
}


Ivan68
  • Members
  • 13 posts
  • Last active: Dec 22 2010 05:59 PM
  • Joined: 15 Jun 2010
It looks working properly now. Many thanks Lexikos, great!

My goal is quite odd. I would like to connect a simple on/off switch to the mic plug and wait for getting it pressed.

Is there any kind of function as:

On event (peak=1.00)
gosub....


Thanks again
Ivan

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Is there any kind of function as:

On event (peak=1.00)
gosub....

No. Use a timer or loop which repeatedly checks the peak value.

Big Digger
  • Members
  • 46 posts
  • Last active: Jul 23 2017 04:06 PM
  • Joined: 07 Feb 2009
Lexikos
Can you please update this library to make it compatible with AHK_L x64?

XavierGr
  • Members
  • 48 posts
  • Last active: Feb 02 2012 04:59 PM
  • Joined: 15 Jul 2006

Lexikos
Can you please update this library to make it compatible with AHK_L x64?


Indeed, this library is very helpfull but won't work with Autohotkey_L x64 Unicode.
One hotkey to rule them all!

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Updated. v2.1 requires AutoHotkey_L but does not require COM.ahk.

Big Digger
  • Members
  • 46 posts
  • Last active: Jul 23 2017 04:06 PM
  • Joined: 07 Feb 2009
Lexikos thank you very much!

XavierGr
  • Members
  • 48 posts
  • Last active: Feb 02 2012 04:59 PM
  • Joined: 15 Jul 2006

Updated. v2.1 requires AutoHotkey_L but does not require COM.ahk.


Much appreciated. :D
One hotkey to rule them all!

  • Guests
  • Last active:
  • Joined: --

Updated. v2.1 requires AutoHotkey_L but does not require COM.ahk.


Thank you so much!

  • Guests
  • Last active:
  • Joined: --
hi!
sorry if this is to basic
but I just want to have a script that when you press "win"+"v" mute the sound of my computer running windows 7
I try with this script:

#v::
VA_SetMasterVolume(0)
return

the error I get is that VA doesn't exit
I copied the VA.ahk to the /lib/ directory under autohokey main path
any help wil be really appreciated
thanks!

  • Guests
  • Last active:
  • Joined: --

hi!
sorry if this is to basic
but I just want to have a script that when you press "win"+"v" mute the sound of my computer running windows 7
I try with this script:

#v::
VA_SetMasterVolume(0)
return

the error I get is that VA doesn't exit
I copied the VA.ahk to the /lib/ directory under autohokey main path
any help wil be really appreciated
thanks!


probelm solve
thanks anyway!

Wazowski
  • Members
  • 42 posts
  • Last active: Apr 14 2016 01:26 AM
  • Joined: 06 Sep 2009

hi!
sorry if this is to basic
but I just want to have a script that when you press "win"+"v" mute the sound of my computer running windows 7
I try with this script:

#v::
VA_SetMasterVolume(0)
return

the error I get is that VA doesn't exit
I copied the VA.ahk to the /lib/ directory under autohokey main path
any help wil be really appreciated
thanks!


probelm solve
thanks anyway!


As Solved ..? I have the same error with the VA pliss help

stevenospam
  • Members
  • 8 posts
  • Last active: Dec 25 2010 11:06 PM
  • Joined: 23 Dec 2010
I'm a total noob. I installed Autohotkey_L and extracted the VA.ahk to the same directory where autohotkey.exe is located. I right click on topology.ahk and immediately get the error message in the subject above. Apparently I'm missing something ...