Apparently this was a very unusual use case, but just in case heres a tip.
I have my PC connected to my TV via HDMI, which means that if I want to watch a movie or something on my TV I can just drag the window across to the TV, maximise it, and it plays. However, the sound always comes out of the default audio device, which in my case is usually the onboard sound card / PC speakers. If I want the sound to come out of my TV, I have to right click the little speaker icon in the system tray, click Playback Devices", select my TV from the list, and then set that as the default device. Then, if Im done watching the film and want to listen to music or play a game, I have to do the same thing to re-set my default device back to my PC speakers.
This is all very tedious, and being a man of a certain disposition, I wanted a programmatic solution. My first instinct was to use AutoHotKey, which is a fantastic piece of software that not only saves me time and effort at home, but also saved the company I work for no less than $1m. I kid you not; we got a quote from our IT consultants that came to at least $1m to replicate the things I was using AutoHotKey for (and without even adding any additional functionality!). Anyway, it turns out that, while AHK can literally provide million-dollar solutions, it cant switch the default audio device in a manner that I wanted. It could replicate the commands and button clicks that are required to do the job i.e. it could perform the actions I outlined earlier (albeit a little more neatly with shortcuts and so on) but it couldnt do this silently, hidden away in the background.
Why is this a problem? It does the job, doesnt it? The control panel flashes up for like, 0.1 seconds, and then disappears, leaving me with the audio coming out of the right place. Job done, right? Yeah, sure, but consider this use case (which has happened, like, every day this week so far). I watch a video on my TV, and I use the script to switch the audio device to the TV. No problem. Now Im done watching stuff on the TV, so I turn it off and load up a full screen computer game. But wait! I forgot to use the script to switch the default audio device back to my PC speakers! Thank goodness I have bound the script to a hotkey! So, I press my hotkey. But because Im in a full screen game, all sorts of shenanigans go on. The script loads up the control panel, stealing focus from my full screen game. This minimises the game, which, if it is being played in a different resolution to the desktop resolution, takes a few seconds as the monitor adjusts to the new resolution. Then it does its thang, but the script requires key presses at various stages to simulate what a human would press, and coming out of full screen and adjusting resolution very often that up. Sure, the script waits for focus before sending keypresses, but because all hell breaks loose window-wise when you go from full screen game back to desktop at a different resolution, they often get missed, get sent to the wrong window, get sent at the wrong time, and so on. So the script doesnt always work.
But even when it does work, Im still left back at the desktop with my fullscreen game running! Games take a lot of CPU cycles, especially on my crappy old Core2duo from like 2007 or whatever that was even 2 years out of date when I bought it. And switching resolutions, loading the desktop, loading the control panel, and then loading the game and switching resolutions again all causes my computer to lose its $%^&.
And then theres the game itself. Like, seriously, games do not appreciate being minimised; anyone whos played a full screen game, even nowadays, will have experienced the trauma that is accidentally pressing the windows key while youre in a full screen game. It takes like a million years to get back up and running in game, and even then, things screw up!
So this solution was inadequate for my use case. My very particular use case. But the great thing about there being 7 billion people on the planet is that a whole bunch of people also have your problems, and out of that bunch of people, some of them will be good enough at programming to come up with a solution. Now, I consider myself good enough at programming to write a noddy little programme that calls some APIs and switches the default audio device. APIs are really easy and Windows is full of them. Surely theres an API for this?
Apparently not. MS has never allowed the default audio device to be changed programmatically, because of the potential scenario of multiple different programs all fighting each other for who gets to set the default audio device. So MS does not release a public API for this. However, thankfully, out of that bunch of people who share my problem, there is at least 1 person who is smart enough to reverse engineer the undocumented API calls that Windows Control Panel makes when it sets the default audio device!
That mans name is Dave Amenta, and this is his solution: a command line programme that takes 1 single parameter and no fussy output, the audio device that you want to set as default:
http://www.daveamenta.com/2011-05/p...e-default-sound-playback-device-in-windows-7/
With this simple .exe, my AHK script was reduced to two lines: just run the .exe with either 1 or 0 as the parameter (as I have only 2 audio playback devices), and set the run option so that the program and output are all complete hidden. Now my hotkey runs silently, and no longer screws up my full screen games!
Thank you, Dave Amenta!