vendredi 30 janvier 2015

Autohotkey Audio Device Numeration keeps changing

I am running an Autohotkey Script to set/changethe Default Audio Device in Windows. It runs very well, unless my USB Hub - where my Headset is attached to - has no power. Then the Device will not appear in the Audio Device overview, which makes sense. But after getting the USB Hub has power again, the numbering of the devices has changed, as my headset now shows up for example at the end of the list. Is there a way to use the name of the audio device instead of the number?


Here is the Autohotkey Script:



;Selects the internal Audio with PageUp
#PgUp up::
SelectAndShowAudioDevice(0,"Headset")
return

;Selects the external Audio with PageDown
#PgDn up::
SelectAndShowAudioDevice(1,"SPDIF-Out")
return

SelectAndShowAudioDevice(deviceNumber, deviceName)
{
error := ActivateAudioDevice(deviceNumber)
if error
TrayTip % "Fehler beim Aktivieren von " . deviceName, % error
else
TrayTip % deviceName . " aktiv", % "Audiowiedergabe erfolgt ueber " . deviceName
}

ActivateAudioDevice(deviceNumber)
{
IfWinNotExist Sound
{
; Öffne Sound Fenster
Run % "RunDll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,0"
WinWait Sound,,2
if ErrorLevel
Return "Sound Fenster nicht gefunden"
CloseSoundWindowAtEnd := True
}

ControlSend SysListView321, {HOME} ; Zum Anfang der Liste mit Pos1
ControlSend SysListView321, {DOWN %deviceNumber%} ; Zum Audiogerät navigieren
SetControlDelay -1 ; Aktiviere schnellen Mausklick
ControlClick Button2 ; Mausklick auf 'Als Standard'

if CloseSoundWindowAtEnd
WinClose
}

Aucun commentaire:

Enregistrer un commentaire