假设我想要热键“Winkey + F1”、“Winkey + F2”和“Winkey + F3”(这样你只需要一只手)在耳机、扬声器和监听音频输出之间切换。我还希望在启动时默认使用耳机。
答案将在下面公布!
创建包含以下内容的 .ahk 文件(例如 ChangeAudioOutput_NirCmd.ahk),同时确保在第 21 行的代码中将
C:\your\path\to\nircmd.exe
更改为安装 nircmd.exe 的位置:
#Requires AutoHotkey v2.0
; ======================================================================================================================
; Everything until the first `return` autoruns
; ======================================================================================================================
; Function definition. Changes Audio Output Device to `device`
; ======================================================================================================================
ChangeAudioOutput(device, show_msg_box:=true)
{
symbols := Map("Headphones", "🎧", "Speakers", "🔊", "Display", "🖥️") ; Python dict-like object, callable by `Val := Array[Key]`
if (show_msg_box)
symbol := symbols[device]
{
; Show a message box
MsgBox(
; MsgBox's message in the box
"Selected device: " symbols[device] device,
; MsgBox's title/heading
"Audio Output Device changed",
; time after which the MsgBox will close
"T0.3"
)
}
Run("C:\your\path\to\nircmd.exe setdefaultsounddevice " device) ; change device using nircmd
}
; set Headphones as default device for startup
ChangeAudioOutput("Headphones", false) ; false -> don't show message box at startup
return ; Everything above this `return` autoruns
; ======================================================================================================================
; ======================================================================================================================
; Audio Output Device Switch to Headphones/Speakers/Monitor
; ======================================================================================================================
; Audio Output Device Switch to Headphones
#F1:: ; Windows key + F1
{
ChangeAudioOutput("Headphones")
}
; Audio Output Device Switch to Speakers
#F2:: ; Windows key + F2
{
ChangeAudioOutput("Speakers")
}
; Audio Output Device Switch to Display/Monitor
#F3:: ; Windows key + F3
{
ChangeAudioOutput("Monitor")
}
确保您所需的音频设备在声音控制面板中被称为准确“耳机”和“扬声器”。到达那里:
为了让此功能在您重新启动电脑后也能正常工作,请执行以下操作:
全部完成!
^F1::; Ctrl + F1 运行,nircmd setdefaultsounddevice“耳机” 返回
^F2::; Ctrl + F2 运行,nircmd setdefaultsounddevice“扬声器” 返回
我正在用这个。