Skip to content

Instantly share code, notes, and snippets.

@xmedeko
Last active March 21, 2023 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmedeko/11814b21b31c14d785019bc2598139d9 to your computer and use it in GitHub Desktop.
Save xmedeko/11814b21b31c14d785019bc2598139d9 to your computer and use it in GitHub Desktop.
AutoHotkey volume by Window key
#Requires AutoHotkey v2.0-
#SingleInstance Force
DEFAULT_VOLUME := 30
; Single press - mute, unmute. Double press - unmute and default volume.
#F1:: {
static winf1_presses := 0
if winf1_presses > 0 { ; Timer already started.
winf1_presses += 1
} else { ; Timer not started.
winf1_presses := 1
SetTimer AfterTimout, -300 ; Wait for more presses within a 400 millisecond window.
}
AfterTimout() {
if winf1_presses = 1 { ; Single press
SoundSetMute -1
} else if winf1_presses >= 2 { ; Double or more presses
SoundSetMute 0
SoundSetVolume DEFAULT_VOLUME
}
winf1_presses := 0 ; Reset the count to prepare for the next series of presses
}
}
; Decrease volume
#F2:: SoundSetVolume "-5"
; Increase volume
#F3:: SoundSetVolume "+5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment