Untitled

 avatar
unknown
plain_text
3 days ago
1.6 kB
3
Indexable
#Requires AutoHotkey v2.0
#SingleInstance Force

; --- STARTUP SYNC ---
Global KefVol := 0
Global IsMuted := false
Global VolumeBeforeMute := 0
SyncWithSpeaker() ; Initial sync

; --- VOLUME UP ---
$Volume_Up:: {
    Global KefVol, IsMuted
    ; If we were muted, turning volume up should "unmute" us
    if (IsMuted) {
        IsMuted := false
    }
    
    KefVol := (KefVol + 2 > 100) ? 100 : KefVol + 2
    Run("kefw2 vol " . KefVol, , "Hide")
}

; --- VOLUME DOWN ---
$Volume_Down:: {
    Global KefVol, IsMuted
    if (IsMuted) {
        IsMuted := false
    }
    
    KefVol := (KefVol - 2 < 0) ? 0 : KefVol - 2
    Run("kefw2 vol " . KefVol, , "Hide")
}

; --- THE MUTE TOGGLE (The Fix) ---
$Volume_Mute:: {
    Global IsMuted, VolumeBeforeMute, KefVol
    
    if (IsMuted) {
        ; UNMUTE: Restore the volume we had before
        KefVol := VolumeBeforeMute
        Run("kefw2 vol " . KefVol, , "Hide")
        IsMuted := false
    } else {
        ; MUTE: Save current volume and drop to 0
        VolumeBeforeMute := KefVol
        KefVol := 0
        Run("kefw2 vol 0", , "Hide")
        IsMuted := true
    }
}

; --- SILENT BRAIN (SYNC) ---
SyncWithSpeaker() {
    Global KefVol
    tempFile := A_Temp "\kef_sync.txt"
    RunWait(A_ComSpec ' /c "kefw2 vol > ' . tempFile . '"', , "Hide")
    if FileExist(tempFile) {
        txt := FileRead(tempFile)
        FileDelete(tempFile)
        if RegExMatch(txt, "\d+", &match)
            KefVol := Number(match[0])
    }
}

; Manual Sync: Ctrl + Alt + S
^!s:: SyncWithSpeaker()
Editor is loading...
Leave a Comment