AutoHotkey音量OSD脚本问题:静音显示异常与滚轮静音需求
问题1:静音时OSD文字不变红的修复
原脚本Volume_Mute函数中的字体更新语法错误,导致颜色未生效。修改该函数如下:
; ▏════════════ Volume Mute ════════════▏ Volume_Mute: SoundSet, +1,, Mute SoundGet, isMuted, MASTER, MUTE If (isMuted = "On") { ; 设置静音时的红色斜体大字体 GuiControl,VOL: Font, Vol, cRed Italic s24 GuiControl,VOL:, Vol, MUTE } else { ; 恢复用户设定的正常字体样式 GuiControl,VOL: Font, Vol, c%Font_Color% s12 Bold SoundGet, Vol GuiControl,VOL:, Vol, % Ceil(Vol) "%" } forceUpdate := 1 Return
错误原因:原代码GuiControl,VOL:, Font, Vol语法不符合AutoHotkey规范,正确格式应为GuiControl [窗口标题] Font, 控件ID, 字体选项。
问题2:鼠标滚轮触发静音的实现
提供两种可选方案,按需选择:
方案1:音量降到0后继续下滚触发静音
修改托盘悬停区域的WheelDown逻辑:
#If ( mouseOverTray = 1 && overTray() ) WheelDown:: SoundGet, CurrentVol, MASTER if (CurrentVol <= 0) { ; 音量已为0,触发静音 Gosub, Volume_Mute } else { SoundSet, -%Amount%, MASTER } SetTimer, Update, -1 Return #If
方案2:滚轮中键点击触发静音
在托盘悬停区域添加滚轮中键热键:
#If ( mouseOverTray = 1 && overTray() ) ; ... 保留原有WheelUp/WheelDown代码 ... WheelClick:: Gosub, Volume_Mute Return #If
完整修改后的脚本
#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 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 ) ; 非静音状态下才更新音量百分比 SoundGet, isMuted, MASTER, MUTE if (isMuted != "On") { 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: SoundSet, +1,, Mute SoundGet, isMuted, MASTER, MUTE If (isMuted = "On") { GuiControl,VOL: Font, Vol, cRed Italic s24 GuiControl,VOL:, Vol, MUTE } else { GuiControl,VOL: Font, Vol, c%Font_Color% s12 Bold SoundGet, Vol GuiControl,VOL:, Vol, % Ceil(Vol) "%" } forceUpdate := 1 Return #If ( mouseOverTray = 1 && overTray() ) ; ▏════════════ Wheel down ════════════▏ WheelDown:: SoundGet, CurrentVol, MASTER if (CurrentVol <= 0) { Gosub, Volume_Mute } else { SoundSet, -%Amount%, MASTER } SetTimer, Update, -1 Return ; ▏════════════ Wheel up ════════════▏ WheelUp:: SoundSet, +%Amount%, MASTER SetTimer, Update, -1 Return ; 可选:取消注释启用滚轮中键静音 ; WheelClick:: ; Gosub, Volume_Mute ; 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
内容的提问来源于stack exchange,提问作者V0RT3X
相关产品推荐
相关产品推荐

