Autohotkey – 如何仅调整特定程序的音量?

我想控制特定程序的音量而不是整个主音量.

我发现THIS线程的代码只能控制Volume Mixer中的Windows Media Player的音量.

这是整个脚本:

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 > 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 < 328
      {
        ToolbarWindowNumber := ToolbarWindowNumber + 2
        msctls_trackbarNumber := msctls_trackbarNumber + 1
      } Else {
        If ToolbarWindowNumber = 328
        {
          ToolbarWindowNumber = 3210
          msctls_trackbarNumber := msctls_trackbarNumber + 1
        } Else {
          If ToolbarWindowNumber < 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 < 328
      {
        ToolbarWindowNumber := ToolbarWindowNumber + 2
        msctls_trackbarNumber := msctls_trackbarNumber + 1
      } Else {
        If ToolbarWindowNumber = 328
        {
          ToolbarWindowNumber = 3210
          msctls_trackbarNumber := msctls_trackbarNumber + 1
        } Else {
          If ToolbarWindowNumber < 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

我尝试了它,它适用于Windows Media Player,但我无法在Google Chrome上运行.

我在IfWinExist,Windows Media Player上更改了一些代码并将其更改为IfWinExist,谷歌Chrome但没有调整Chrome的音量.

我正在运行Windows 10 64位

最佳答案 >替换所有IfWinExist,Windows Media Player

使用IfWinExist ahk_class Chrome_WidgetWin_1

>替换Windows Media Player的所有If ControlName = Mute

with if(ControlName〜=“Mute for.* – Google Chrome”)

您可以使用Autohotkey Window Spy实用程序查找值.右键单击任务栏托盘通知区域中的任何AHK图标,然后选择“Window Spy”.

或者使用awesome nircmd实用程序:

^#Up::run nircmd changeappvolume focused +0.1
^#Down::run nircmd changeappvolume focused -0.1
^#Numpad0::run nircmd muteappvolume focused 2

Ctrl Win Up =音量调高活动应用
Ctrl Win Down =音量减小活动应用
Ctrl Win Numpad 0 =静音/取消静音活动应用

将app重点替换为app exe名称以控制特定应用,例如chrome.exe,vlc.exe

点赞