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.
setdefaultsounddevice [Device Name]
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 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 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.