Search code examples
user-interfaceautohotkey

How do I edit the Gui name of an existing AutoHotkey script?


I came across a great little OSD volume script that I would like to incorporate into a larger script I'm working on. Unfortunately, I am running into issue with this script's Gui needing named different than what will be the parent. I thought it would be as simple as putting this as seen in documentation at the start of the volume section...

Gui, New 
Gui, VOL:New

and just changing all the "Gui, " to something like "Gui VOL:" When I do get something to successfully work, it brings up the Gui when hovering over the taskbar and shows the volume level, but I am unable to change the volume at this point. Posted below is the working version of the volume script. If there is something else that needs modified I'm not seeing it and would love to be pointed in the right direction. -Thank You!!

; SOURCE: https://www.autohotkey.com/board/topic/94813-just-another-volume-osd/
#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, Color, % Back_Color, 
Gui, Font, c%Font_Color% s10 Bold
Gui, Add, Text, w%Control_W% Center, Volume
Gui, Font
Gui, Add, Progress, w%Control_W% vProgress c%Bar_Color% +Background%BackBar_Color%, % Curr_Vol
Gui, Font, c%Font_Color% s12 Bold
SoundGet, Vol
Gui, Add, Text, w%Control_W% Center vVol, % Floor( vol ) "%"
Gui, +AlwaysOnTop -Caption +E0x20 -SysMenu +ToolWindow
Gui, 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,, Progress, % Ceil( Vol )
        GuiControl,, 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}
    SoundGet, isMuted, MASTER, MUTE
    Gui, Font
    If ( isMuted = "On" )
        Gui, Font, cRed Italic s24
    else
        Gui, Font, c%Font_Color% s24 Bold
        GuiControl, 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
    Return
^Esc::  
        ExitApp
    Return

Solution

  • GuiControl says:

    To operate upon a window other than the default, include its name or number (or in [v1.1.03+] its HWND) followed by a colon in front of the sub-command as in these examples:

    GuiControl, MyGui:Show, MyButton
    GuiControl, MyGui:, MyListBox, Item1|Item2
    
    ; SOURCE: https://www.autohotkey.com/board/topic/94813-just-another-volume-osd/
    #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}
        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