Search code examples
windowsautohotkey

(AHK) shortening this autohotkey script, possible?


^+a::
soundset +8
soundget vol
tooltip % "volume = " round(vol), 1900, 1000

settimer, removetooltip1, -3000
return
removetooltip1:
tooltip
return

^+s::
soundset -8
soundget vol
tooltip % "volume = " round(vol), 1900, 1000

settimer, removetooltip2, -3000
return
removetooltip2:
tooltip
return

^+c::
soundset, +1,, mute
soundget, mutestate, master, mute
if mutestate=on
tooltip sound = off, 1900, 1000
else
tooltip sound = on, 1900, 1000

settimer, removetooltip3, -3000
return
removetooltip3:
tooltip
return

With this script, when you change the volume or mute using hotkeys, small tooltip pops up informing the current volume or mute/unmute status.

It works without any issues, but I wonder if it is possible to combine three of them, maybe by using settimer just once to avoid unnecessary(if any) duplication?

maybe something like this

(
^+a::
....
....
^+s::
....
....
^+c::
....
....
)

settimer, removetooltip, -3000
return
removetooltip:
tooltip
return

As you may see I am obviously noob. I need help please :)


Solution

  • You need only one timer for removing the ToolTip:

    ^+a::
        soundset +8
        soundget vol
        tooltip % "volume = " round(vol), 1900, 1000
        settimer, removetooltip, -3000
    return
    
    ^+s::
        soundset -8
        soundget vol
        tooltip % "volume = " round(vol), 1900, 1000
        settimer, removetooltip, -3000
    return
    
    ^+c::
        soundset, +1,, mute
        soundget, mutestate, master, mute
        if mutestate=on
            tooltip sound = off, 1900, 1000
        else
            tooltip sound = on, 1900, 1000
        settimer, removetooltip, -3000
    return
    
    removetooltip:
        tooltip
    return