Setting the volume of a specific window/application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krypton091
Posts: 1
Joined: 23 Apr 2018, 18:42

Setting the volume of a specific window/application

23 Apr 2018, 18:48

I'm currently trying to be able to lower or raise the volume of Amazon Music instead of my entire computer.

I get that

Code: Select all

^Down::SoundSet -5
would lower my Windows volume by -5, but can I make it so this only goes to Amazon Music? I've searched on YouTube, Google, this forum, etc. but I can't seem to find a way to get a way for it to work. I tried http://john-d-amos.blogspot.com/2015/02 ... a-one.html yet that didn't even work for me. Any help?

EDIT: Also, I realize Amazon Music has built in shortcuts like this, but I find the volume changes too drastically and I'd like the intervals to be smaller, hence why I'm trying to use AHK
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Setting the volume of a specific window/application

24 Apr 2018, 02:51

The following function works. Note that this increment is based on the range of the current master volume for the device it's running through. Meaning, if the current master volume is 20 (0.20), 0.0 = 0, and 1.0 = 20. Open the mixer and watch it if you don't know what I mean.

Code: Select all

; example
F1::setWindowVol("ahk_exe vlc.exe","+10") ; add 10 (percent)
F2::setWindowVol("ahk_exe vlc.exe","-10") ; subtract 10 (percent)
F3::setWindowVol("ahk_exe vlc.exe",15) ; set to 15 (percent)

; function

#include <VA> ; https://autohotkey.com/board/topic/21984-vista-audio-control-functions/

setWindowVol(winName:="a",vol:="n"){
    if(vol=="n")
        return
    winGet,winPid,PID,% winName
    if !(volume:=GetVolumeObject(winPid)) ; get volume object of pid
        return
    vsign:=subStr(vol,1,1) ; get sign
    if(vsign="+"||vsign="-"){
        vol:=subStr(vol,2),vol/=100 ; remove sign from vol and make decimal
        
        VA_ISimpleAudioVolume_GetMasterVolume(volume,cvol) ; get current volume level
        if(vsign="+")
            vol:=cvol+vol>1?1:cvol+vol ; add given amount to current volume
        else if(vsign="-")
            vol:=cvol-vol<0?0:cvol-vol ; subtract given amount from current volume
    }else
        vol/=100
    VA_ISimpleAudioVolume_SetMasterVolume(volume,vol) ; set new volume level
    objRelease(volume)
}
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 310 guests