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

标签 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, Google Chrome但没有调整Chrome的音量。

我正在运行 Windows 10 64 位

最佳答案

  • 全部替换 IfWinExist, Windows Media PlayerIfWinExist ahk_class Chrome_WidgetWin_1
  • 全部替换 If ControlName = Mute for Windows Media Playerif (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
    

    Ctrl+Win+Up = 提高事件应用的音量
    Ctrl+Win+Down = 降低事件应用程序的音量
    Ctrl+Win+Numpad 0 = 静音/取消静音事件应用程序

    替换 focused使用 app exe 名称来控制特定的应用程序,例如chrome.exe , vlc.exe

    关于Autohotkey - 如何仅调整特定程序的音量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38433170/

    相关文章:

    download - UrlDownloadToFile 的替代方案

    lotus-notes - 为 "reply to all with history"创建 Lotus Notes 热键/快捷键

    Autohotkey - 将剪贴板格式的文本转换为纯文本

    windows - 使用 Windows 7 的 AHK 交换 Ctrl 和 Capslock 以进行远程访问 session

    autohotkey - 向上/向下键在 Onenote 2016 中对于 Autohotkey 不起作用

    visual-studio - 为什么 Visual Studio 在自动热键之前捕获关键事件?

    autohotkey - Spotify 中下一首歌曲的热键

    window - 如何使用 AutoHotkey 锁定我的计算机?

    autohotkey - 如何使用 AutoHotkey 删除当前行?

    autohotkey - ControlSend 发送额外的换行符