AutoHotKey includes some built-in commands for controlling audio devices on a PC. Although there are several device and control types, I could only get it to work with "master" speakers. There's a lot I don't understand about how Windows thinks about audio devices, but using "master" for the speakers is OK with me.
- Most applications provide no control for audio output, and most also don't even provide any UI feedback on the state of audio output. They seem to feel like it's Somebody Else's Problem.
- I use a variety of different "speakers" from time to time (multiple headphones, built-in laptop speakers, HDMI audio to my monitor). I'm skeptical about being able to control the right device at the right time. (In fact, even as a PC user operating the controls with my mouse, I find things get kind of bonkers sometimes.)
- The "master" control provides visual feedback in the little speaker icon in the system tray.
The AHK SoundSet command will let you explicitly turn speakers on or off, and it also will let you toggle things. Even though I have disparaged hotkey toggles, I found it convenient to use it for implementing speaker control in this AHK function. SoundGet returns either "On" or "Off" for the state of muting of the speakers. To unmute the speakers, we want to "turn off the mute function".
; Control-Shift-F11 mute speakers ^+F11:: SpeakerControl("On") return ;;;;;;;;;;;;;;;;;;; ; Control-Shift-F12 unmute speakers ^+F12:: SpeakerControl("Off") return SpeakerControl(StateWanted) { ; mute state "On" means the speakers are muted ; mute state "Off" means the speakers are not muted SoundGet, MUTE_STATE ,,MUTE if (StateWanted != MUTE_STATE) { ; this toggles mute state, so we only do it if appropriate SoundSet, +1, ,MUTE } }
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.