2017-08-12 60 views
0

我需要使用熱鍵來切換聲源。這樣的腳本:AutoHotKye - 如何在系統聲源之間切換

F6:: 
Run, mmsys.cpl 
WinWait,Sound 
ControlSend,SysListView321,{Down 2} 
ControlClick,&Set Default 
ControlClick,OK 
return 

F7:: 
Run, mmsys.cpl 
WinWait,Sound 
ControlSend,SysListView321,{Down 5} 
ControlClick,&Set Default 
ControlClick,OK 
return 

不工作。他們剛開始 '聲音設備' 窗口

回答

0

需要一個庫VA:

F6:: 
loop 
MsgBox % SwapAudioDevice("Speakers", "Digital Output") 

SwapAudioDevice(device_A, device_B) 
{ 
; Get device IDs. 
A := VA_GetDevice(device_A), VA_IMMDevice_GetId(A, A_id) 
B := VA_GetDevice(device_B), VA_IMMDevice_GetId(B, B_id) 
if A && B 
{ 
    ; Get ID of default playback device. 
    default := VA_GetDevice("playback") 
    VA_IMMDevice_GetId(default, default_id) 
    ObjRelease(default) 
    ; If device A is default, set device B; otherwise set device A. 
    VA_SetDefaultEndpoint(default_id == A_id ? B : A, 0) 
} 
ObjRelease(B) 
ObjRelease(A) 
if !(A && B) 
    throw Exception("Unknown audio device", -1, A ? device_B : device_A) 
Return default_id == A_id ? device_B : device_A 
} 
Return