title: Autohotkey - How to adjust volume only of a specific program?
body: <p>I want to control volume of a specific program and not the whole master volume.</p>
  
  <p>I found <a href="https://autohotkey.com/board/topic/56889-application-specific-sound-control-for-windows-7-rev-101/" rel="noreferrer">THIS</a> thread that has code for controlling only the volume of Windows Media Player from Volume Mixer .</p>
  
  <p>This is the whole script:</p>
  
  <pre><code>SetTitleMatchMode, 3
  SndVolWasStarted = 0
  
  ;Turn off SndVol after 1 second 
  Loop {
    Sleep, 10
    If SndVolWasStarted = 1
    {
      GetKeyState, StateF1, F1
      GetKeyState, StateF2, F2
      If (StateF1 = "D" or StateF2 = "D")
      SndVolStartTime = %A_Now%
        Else {
          If ((A_Now - SndVolStartTime &gt; 1) and WinExist("ahk_class #32770"))
          WinClose, ahk_class #32770
        }
      IfWinNotExist, ahk_class #32770
      SndVolWasStarted = 0
    }
  }
  
  ;Hotkey to decrease volume
  F1::
  IfWinExist, Windows Media Player 
  {
    IfWinNotExist, ahk_class #32770
    {
      Run, "%A_WinDir%\System32\SndVol.exe" -r 88888888
      WinWait, ahk_class #32770
      SndVolWasStarted = 1
    }
    ToolbarWindowNumber = 322
    msctls_trackbarNumber = 321
    Loop {
      ControlGetText, ControlName, ToolbarWindow%ToolbarWindowNumber%, ahk_class #32770
      If ControlName = Mute for Windows Media Player
      {
        ControlSend, msctls_trackbar%msctls_trackbarNumber%, {Down}, ahk_class #32770 ; Use {Down 2} to change sound level faster
        Break
      } Else {
        If ToolbarWindowNumber &lt; 328
        {
          ToolbarWindowNumber := ToolbarWindowNumber + 2
          msctls_trackbarNumber := msctls_trackbarNumber + 1
        } Else {
          If ToolbarWindowNumber = 328
          {
            ToolbarWindowNumber = 3210
            msctls_trackbarNumber := msctls_trackbarNumber + 1
          } Else {
            If ToolbarWindowNumber &lt; 3242
            {
              ToolbarWindowNumber := ToolbarWindowNumber + 2
              msctls_trackbarNumber := msctls_trackbarNumber + 1
            } Else {
              MsgBox, 16, AutoHotkey, ERROR: Application's volume control was not found!`nThis could occur if the Volume Mixer has more than 20 opened applications
              Break
            }
          }
        }
      }
    }
  }
  Return
  
  ;Hotkey to increase volume
  F2::
  IfWinExist, Windows Media Player
  {
    IfWinNotExist, ahk_class #32770
    {
      Run, "%A_WinDir%\System32\SndVol.exe" -r 88888888
      WinWait, ahk_class #32770
      SndVolWasStarted = 1
    }
    ToolbarWindowNumber = 322
    msctls_trackbarNumber = 321
    Loop {
      ControlGetText, ControlName, ToolbarWindow%ToolbarWindowNumber%, ahk_class #32770
      If ControlName = Mute for Windows Media Player
      {
        ControlSend, msctls_trackbar%msctls_trackbarNumber%, {Up}, ahk_class #32770 ; Use {Up 2} to change sound level faster
        Break
      } Else {
        If ToolbarWindowNumber &lt; 328
        {
          ToolbarWindowNumber := ToolbarWindowNumber + 2
          msctls_trackbarNumber := msctls_trackbarNumber + 1
        } Else {
          If ToolbarWindowNumber = 328
          {
            ToolbarWindowNumber = 3210
            msctls_trackbarNumber := msctls_trackbarNumber + 1
          } Else {
            If ToolbarWindowNumber &lt; 3242
            {
              ToolbarWindowNumber := ToolbarWindowNumber + 2
              msctls_trackbarNumber := msctls_trackbarNumber + 1
            } Else {
              MsgBox, 16, AutoHotkey, ERROR: Application's volume control was not found!`nThis could occur if the Volume Mixer has more than 20 opened applications
              Break
            }
          }
        }
      }
    }
  }
  Return
  </code></pre>
  
  <p>I tried it and it works with Windows Media Player but I can't make it to work on Google Chrome. </p>
  
  <p>I changed some piece of code on <code>IfWinExist, Windows Media Player</code> and changed it to <code>IfWinExist, Google Chrome</code> but didn't adjust the volume of Chrome.</p>
  
  <p>I'm running windows 10 64-bit</p>