autohotkeyvolumemousewheelmute

OSD volume bar to mousewheel into mute?


I have an older OSD volume script that works wonderfully and is very customizable. Original found here... SOURCE: https://www.autohotkey.com/board/topic/94813-just-another-volume-osd/

My only issue is when the volume gets muted, the ODS should turn red but doesn't and I can't figure out why. I also would like to be able to mute with the mousewheel, the same way the volume gets adjusted up and down. Can someone with more experienced eyes take a look and tell me if I can even get that with this script as doing so with the inbuilt volume control also doesn't go into mute when scrolled all the way down? Thank you for reading about my dilemma.

the script...

#SingleInstance, Force
SetBatchLines, -1

; ▏════════════ User Variables ( Change as needed ) ════════════▏ 

Gui_W                := A_ScreenWidth / 2 - 500
Gui_X                := A_ScreenWidth - gui_W - 16
Gui_Y                := A_ScreenHeight - 120
; ─ ─ ─ ─ ─ ─ 
Back_Color            := 0x000000
Font_Color            := 0x4499FF
BackBar_Color        := 0x000000
Bar_Color            := 0x005AC7
RoundedGui            := 3
; ─ ─ ─ ─ ─ ─ 
VolUp_Key            := "^!=" 
VolDown_Key            := "^!-"
muteKey             := "^!0" 
Amount                := 1 
; ─ ─ ─ ─ ─ ─ 
Update_Freq            := 1
Timeout                := 1500
Max_Trans            := 200
; ─ ─ ─ ─ ─ ─ 
mouseOverTray         := 1

; ▏════════════ End of user variables ════════════▏ 

Gui_X                := Gui_X ? "x" Gui_X : ""
Gui_Y                 := Gui_Y ? "y" Gui_Y : ""
Update                 := 0

SoundGet, Vol
Curr_Vol            := Vol
Trans                 := 0
Control_W            := GUI_W - 30

; ▏════════════ Volume GUI ════════════▏ 
Gui,VOL: Color, % Back_Color, 
Gui,VOL: Font, c%Font_Color% s10 Bold
Gui,VOL: Add, Text, w%Control_W% Center, Volume
Gui,VOL: Font
Gui,VOL: Add, Progress, w%Control_W% vProgress c%Bar_Color% +Background%BackBar_Color%, % Curr_Vol
Gui,VOL: Font, c%Font_Color% s12 Bold
SoundGet, Vol
Gui,VOL: Add, Text, w%Control_W% Center vVol, % Floor( vol ) "%"
Gui,VOL: +AlwaysOnTop -Caption +E0x20 -SysMenu +ToolWindow
Gui,VOL: Show, NoActivate h80 w%Gui_W% %Gui_X% %Gui_Y% , Vol_OSD
; +AlwaysOnTop 
If ( RoundedGui )
    WinSet, Region, w%Gui_W% h100 R10-10 0-0, Vol_OSD
WinSet, Transparent, %Trans%, Vol_OSD

; ▏════════════ Sets the Hotkeys ════════════▏ 
Hotkey, % VolUp_Key, Volume_Up
Hotkey, % VolDown_Key, Volume_Down
Hotkey, % muteKey, Volume_Mute
SetTimer, Update, % Update_Freq
SetTimer, Fade, % "-" Timeout
Return

; ▏════════════ GUI fadeout ════════════▏ 
Fade: 
    While ( Trans > 0 && Update = 0)
    {    Trans -= A_Index / 4
        WinSet, Transparent, % Trans, Vol_OSD
        Sleep, 5
    } 
Return

; ▏════════════ Update ════════════▏ 
Update: 
    SetTimer, Update, % Update_Freq
    Update                := 0
    SoundGet, Vol
    If ( Vol <> Curr_Vol || forceUpdate = 1)
    {    Update             := 1
        GuiControl,VOL:, Progress, % Ceil( Vol )
        GuiControl,VOL:, Vol, % Ceil( Vol) "%"
        Curr_Vol         := Vol
        While ( Trans < Max_Trans )
        {    Trans         += A_Index * 2
            WinSet, Transparent, % Trans, Vol_OSD 
            Sleep 1
        } 
        SetTimer, Fade, % "-" Timeout
        forceUpdate             := 0
    } 
Return

; ▏════════════ Volume Down ════════════▏ 
Volume_Down:
    SoundSet, -%Amount%, MASTER
    SetTimer, Update, -1
Return

; ▏════════════ Volume Up ════════════▏ 
Volume_Up:
    SoundSet, +%Amount%, MASTER
    SetTimer, Update, -1
Return

; ▏════════════ Volume Mute ════════════▏ 
Volume_Mute:
    ;Send, {Volume_Mute}
    SoundSet, +1,, Mute
    SoundGet, isMuted, MASTER, MUTE
    Gui,VOL: Font
    If (isMuted = "On")
        Gui,VOL: Font, cRed Italic s24
    else
        Gui,VOL: Font, c%Font_Color% s24 Bold
    GuiControl,VOL:, Font, Vol
    forceUpdate := 1
Return


#If ( mouseOverTray = 1 && overTray() )
; ▏════════════ Wheel down ════════════▏ 
WheelDown::    
    SoundSet, -%Amount%, MASTER
    SetTimer, Update, -1
Return

; ▏════════════ Wheel up ════════════▏ 
WheelUp::
    SoundSet, +%Amount%, MASTER
    SetTimer, Update, -1
Return
#If 

; ▏════════════ overTray Function  ════════════▏ 
overTray()
{    MouseGetPos, mX, mY, mWin
    WinGetClass, wClass, ahk_id %mWin%
    Return % wClass = "Shell_TrayWnd" ? 1 : 0
}
RETURN

^Home:: Reload

^Esc:: ExitApp

Solution

  • @scso ...I had that initial thought momentarily too, but then brushed it off as feeling it's no different than something like...

    Gui, +AlwaysOnTop vs Gui +AlwaysOnTop

    Both do the same thing and the comma in this scenario is a personal preference.

    @user3419297 ...thank you as always. Sadly this induced a significant amount of flicker, regardless of how I altered it, but it did indeed give an actual muting and turned red. I gave up and started over going with a simpler approach. I don't get the red when it goes mute, but at least it does mute without all the flickering. The below is what I ended up going with. Thank you again!!

    (And considering I was docked a couple points for posting a question using polite manners such as "Hello and good day" and they referenced it as "fluff", not sure thanking is actually allowed on here. Oh well, guess that individual just needs a hug so they can get on with life. Long story short... THANK YOU!!)

    #NoEnv
    #SingleInstance, Force
    
    Gui, +AlwaysOnTop 
    CoordMode, Mouse, Screen
    
    BarX := ((A_ScreenWidth / 20) * 19) - 185    ; Adjust the 185 as needed for 'X'.
    BarY := (A_ScreenHeight / 20) + 932      ; Adjust the 932 as needed for 'Y'.
    
    Volume_ProgressbarOpts = CW0D0D0D CT00FFDC CB42B4FF x%BarX% y%BarY% w260 h52 B1 FS8 WM700 WS700 FM8 ZH12 ZY3 C11
    
    Progress Hide %Volume_ProgressbarOpts%,,Volume, ,Segoe UI
    
    #If MouseIsOverBottom()
    ^WheelUp::
        ChangeVolume("+")
            GoSub, Volume_Show_OSD
    Return
    ^WheelDown::
        ChangeVolume("-")
            GoSub, Volume_Show_OSD
    Return
    #If
    
    ChangeVolume(x)
    {  SoundGet, vol, Master, Volume
       if (x = "+")
         nd := Round(vol) < 20 ? 1 : 5
       else
         nd := Round(vol) <= 20 ? 1 : 5
       nv = %x%%nd%
       SoundSet, nv, Master, Volume
       SoundSet, 0, Master, Mute
       SoundGet, vol
       SoundSet, !(vol/vol),, Mute
    }
    
    MouseIsOverBottom()
    {  MouseGetPos,,y
       Return y > A_ScreenHeight - 40
    }
    
    Volume_Show_OSD:
      SoundGet, Volume, Master, Volume
      Progress % Volume := Round(Volume), %Volume% `%
      Progress Show
      SetTimer, Remove_Show_OSD, 3900
    Return
    
    Remove_Show_OSD:
      SetTimer, Remove_Show_OSD, Off
      Progress Hide %Volume_ProgressbarOpts%,,Volume,,Segoe UI
    Return