Switch playback device using Logitech G key
Getting started
First you need to download NirCmd. It doesn't require any installation.
NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface.
NirCmd has a nifty command called setdefaultsounddevice
which we need.
Manpage
setdefaultsounddevice [Device Name] {Role}
Set the default sound device on Windows 7/Vista/2008. The [Device Name] is the name of the device, as appeared in the sound devices list of windows, for example: Speakers, Line In, Microphone, and so on... The {Role} parameter is optional and may countain one of the following values: 0 for Console (the default value), 1 for Multimedia, and 2 for Communications.
Once you've downloaded the program you can put it in either your windows folder or a folder of your choosing. If you put it in your windows folder you don't have to know the location of the nircmd.exe file. More on that later.
Finding [Device Name]
Now we need to find your [Device Name]. Go to: Control Panel\Hardware and Sound\Sound and locate your devices. They'll most likely be called Speakers.
You'll need to change one of the names. I prefer to change the onboard sound device because once you unplug USB headset and plug it back in the device name will have reset to Speakers. You rename a device by choosing properties on the device and typing in the name you want in the top field.
When that's done you should have two playback devices, one called Speakers (headset) the other LoudSpeakers.
Using NirCmd
We can now use NirCmd to switch to the desired device. Like so:
> nircmd.exe setdefaultsounddevice Speakers
However I found that Skype (In my case) doesn't change when this is run. So we need to use the optional {Role} parameter as well.
> nircmd.exe setdefaultsounddevice Speakers
> nircmd.exe setdefaultsounddevice Speakers 2
Luckily NirCmd support scripts. So lets create two scripts one that switches to our speakers and one that switches to our headset.
SwitchToHeadset.ncl:
setdefaultsounddevice "Speakers"
setdefaultsounddevice "Speakers" 2
SwitchToSpeakers.ncl:
setdefaultsounddevice "LoudSpeakers"
setdefaultsounddevice "LoudSpeakers" 2
You can create these using Notepad. They're just text files with a .ncl extension instead of .txt. Put them in a convenient location. We'll need the shortly.
Switch playback device using the Logitech G keys
Depending on your decision where to place the nircmd.exe file the following may differ. I'll be using the solution where I don't place nircmd.exe in the windows folder.
Now you need to go to the Logitech Gaming Software (driver) to bind your G keys to these scripts. Select the button you want to bind and choose Shortcut, choose an appropriate name and type in the path to nircmd.exe and the .ncl script in want to run.
"X:/Audio switch/nircmd.exe" script "X:/Audio switch/SwitchToSpeakers.ncl"
Remember to bind both SwitchToHeadset and SwitchToSpeakers.
You're done! Enjoy.
I found an easier solution.
I used this helpful little app here (audioswitcher) and I mapped the sound setting to some keystrokes, and then mapped them to the buttons on the side of the headset.
Same end result, but an easier path to get there, and the app is useful anyway if you have numerous sound output devices to manage.
Here is another alternative using a different program called "Audioswitch":
Download & Install Audioswitch https://github.com/sirWest/AudioSwitch/releases
Open Audioswitch settings from the taskbar menu and disable all the audio devices you DON'T want it to switch to. (Be sure to click "Save Setting" in bottom right corner after disabling each unwanted device.)
Go to the "Hot Keys" tab and choose either "PreviousPlaybackDevice" or "NextPlaybackDevice" (it doesn't matter) and make a hotkey for it. (I choose to use "Shift+F3" but feel free to use any combo you like.) Exit the menu by clicking "Apply Hotkeys & Close".
Open Logitech Gaming Software and set your preferred Logitech "G" key to mimic whatever key(s) you choose to use from the "Hot Key" menu in the previous step. (I choose to map this to the "G3" key because it was my next available.)