Setting the volume of a specific window/application

Get help with using AutoHotkey and its commands and hotkeys
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 ... 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
Posts: 1433
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

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> ;

    winGet,winPid,PID,% winName
    if !(volume:=GetVolumeObject(winPid)) ; get volume object of pid
    vsign:=subStr(vol,1,1) ; get sign
        vol:=subStr(vol,2),vol/=100 ; remove sign from vol and make decimal
        VA_ISimpleAudioVolume_GetMasterVolume(volume,cvol) ; get current volume level
            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
    VA_ISimpleAudioVolume_SetMasterVolume(volume,vol) ; set new volume level
OS: Windows 7 Ultimate | Editor: Notepad++
My Personal Function Library | Check Out My Computer Rig
User avatar
Posts: 1044
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina

Re: Setting the volume of a specific window/application

24 Apr 2018, 03:47

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], firewater, futuretech85, Google [Bot] and 168 guests