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

chi*_*ico 5 autohotkey

我要控制特定程序的音量,而不是整个主音量。

我发现线程具有用于仅从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
Run Code Online (Sandbox Code Playgroud)

我尝试过,它可以与Windows Media Player一起使用,但是无法使其在Google Chrome上运行。

我更改了一些代码IfWinExist, Windows Media Player并将其更改为,IfWinExist, Google Chrome但没有调整Chrome的音量。

我正在运行Windows 10 64位

wOx*_*xOm 5

  1. 全部替换IfWinExist, Windows Media Player
    IfWinExist ahk_class Chrome_WidgetWin_1
  2. 全部替换If ControlName = Mute for Windows Media Player
    if (ControlName ~= "Mute for.*- Google Chrome")

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


或者使用很棒的nircmd实用程序:

^#Up::run nircmd changeappvolume focused +0.1
^#Down::run nircmd changeappvolume focused -0.1
^#Numpad0::run nircmd muteappvolume focused 2
Run Code Online (Sandbox Code Playgroud)

Ctrl+ Win+ Up= 调高活动应用程序的音量
Ctrl+ Win+ Down= 调低活动应用程序的音量
Ctrl+ Win+ Numpad 0= 静音/取消静音活动应用程序

替换focused为应用程序 exe 名称以控制特定应用程序,例如chrome.exevlc.exe