|XP is just a number|
Programmatically enable/disable a playback device in Windows 7by thmsdrew (Scribe)
|on Nov 08, 2012 at 13:34 UTC||Need Help??|
thmsdrew has asked for the
wisdom of the Perl Monks concerning the following question:
Hello folks. My goal is to programmatically enable or disable playback devices in Windows 7. I have headphones and speakers that I switch between frequently enough that it would be nice to automate it. Right now, if I want to switch between the two, I have to right-click the sound icon in my taskbar, click "Playback devices", right-click the currently enabled device, disabling it, and then right-click the disabled one, enabling it.
I've already looked into Microsoft's DevCon tool. It almost does what I describe, except it can only enable/disable the entire HDAUDIO device. I want to enable/disable either "Headphones" or "Speakers", which I don't think are given individual device IDs.
I did a bit of CPAN searching and didn't find much. I'm thinking maybe there's an automation "suite" that can access windows and click stuff within them. (XPath or something).
Edit: I can programmatically open up the sound options window I'm talking about with the following command:C:\> control mmsys.cpl
Just need to be able to identify entities within the window and left- or right-click on them. I think Win32::GuiTest can do that.
Double Edit: This is how I am doing it, for anyone that still cares: