OSD音量条到鼠标滚轮进入静音?

OSD volume bar to mousewheel into mute?

提问人:V0RT3X 提问时间:8/1/2023 最后编辑:FilburtV0RT3X 更新时间:8/3/2023 访问量:66

问:

我有一个较旧的 OSD 卷脚本,它运行良好且非常可定制。原件在这里找到...来源:https://www.autohotkey.com/board/topic/94813-just-another-volume-osd/

我唯一的问题是当音量静音时,ODS 应该变成红色,但没有,我不知道为什么。我还希望能够使用鼠标滚轮静音,就像上下调节音量一样。有更有经验的人可以看一看,告诉我我是否可以用这个脚本来做到这一点,因为使用内置的音量控制这样做也不会在一直向下滚动时进入静音状态?感谢您阅读我的困境。

剧本...

#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
自动热键 音量 鼠标滚轮 静音

评论

0赞 scso 8/2/2023
显然是逗号的错别字?你有而不是GuiControl,VOL:, Font, VolGuiControl,VOL: Font, Vol

答:

1赞 Relax 8/2/2023 #1

试试这个:

; 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 - 180
; ─ ─ ─ ─ ─ ─ 
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
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
SoundGet, Vol
Gui,VOL: Add, Text, w%Control_W% Center vVol, % Floor( vol ) "%"
Gui,VOL: +AlwaysOnTop -Caption +E0x20 -SysMenu +ToolWindow
Gui,VOL: Show, NoActivate h90 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:
    SoundGet, isMuted,, MUTE
    Gui,VOL: Font
    If ( isMuted = "On" )
        Gui,VOL: Font, cRed Italic s16
    else
        Gui,VOL: Font, c%Font_Color% s16
     GuiControl,VOL: Font, Vol
    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
    Send {Volume_Down}
    SetTimer, Update, -1
Return

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

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

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

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

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

^Home:: Reload

^Esc:: ExitApp
1赞 V0RT3X 8/3/2023 #2

@scso......我最初也有这个想法,但后来把它刷掉了,因为我觉得这和类似的东西没有什么不同......

Gui, +AlwaysOnTopGui +AlwaysOnTop

两者都做同样的事情,在这种情况下,逗号是个人偏好。

@user3419297......一如既往地谢谢你。可悲的是,无论我如何改变它,这都会引起大量的闪烁,但它确实给出了实际的静音并变红了。我放弃了,开始采用更简单的方法。当它静音时,我没有得到红色,但至少它确实静音而没有闪烁。以下是我最终选择的内容。再次感谢!!

(考虑到我因使用礼貌的方式发布问题(例如“你好,美好的一天”)而被扣了几分,他们将其称为“绒毛”,不确定这里是否真的允许感谢。哦,好吧,猜猜那个人只需要一个拥抱,这样他们就可以继续生活。长话短说。。。谢谢!!

#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

评论

1赞 scso 8/7/2023
冒号后面的逗号很重要。Name:是 SubCommand 参数的一个。分号后面的逗号传递空白子命令,其作用与 Font 子命令不同。
1赞 V0RT3X 8/7/2023
感谢您的更正。我后来回去回顾了你的观察结果,我以前戴着眼罩看。因此,虽然我用 +AlwaysOnTop 显示的内容是正确的,因为它有效,但如果我开始添加添加、字体等内容,一切都会改变,并让我用更愚蠢的回答提出愚蠢的问题。哈哈。对不起,谢谢你纠正我!!