有些窗口希望它静音或者减少音量,可以用下面这个函数
If (!A_IsAdmin)
{
MsgBox Run the Script as Administrator!
ExitApp
}
;这里输入需要改变音量的进程
Process Exist, Game.exe
ProcessId := ErrorLevel
If (!ProcessId)
{
MsgBox Game is not running!
ExitApp
}
SetAppVolume(ProcessId, Volume:=100)
;这里修改改变音量的热键和增减幅度
F1::SetAppVolume(ProcessId, Volume := (Volume == 100 ? 100 : Volume + 10))
F2::SetAppVolume(ProcessId, Volume := (Volume == 0 ? 0 : Volume - 10))
SetAppVolume(PID, MasterVolume) ; WIN_V+
{
MasterVolume := MasterVolume > 100 ? 100 : MasterVolume < 0 ? 0 : MasterVolume
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+4*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 1, "UPtrP", IMMDevice, "UInt")
ObjRelease(IMMDeviceEnumerator)
VarSetCapacity(GUID, 16)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}", "UPtr", &GUID)
DllCall(NumGet(NumGet(IMMDevice+0)+3*A_PtrSize), "UPtr", IMMDevice, "UPtr", &GUID, "UInt", 23, "UPtr", 0, "UPtrP", IAudioSessionManager2, "UInt")
ObjRelease(IMMDevice)
DllCall(NumGet(NumGet(IAudioSessionManager2+0)+5*A_PtrSize), "UPtr", IAudioSessionManager2, "UPtrP", IAudioSessionEnumerator, "UInt")
ObjRelease(IAudioSessionManager2)
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+3*A_PtrSize), "UPtr", IAudioSessionEnumerator, "UIntP", SessionCount, "UInt")
Loop % SessionCount
{
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+4*A_PtrSize), "UPtr", IAudioSessionEnumerator, "Int", A_Index-1, "UPtrP", IAudioSessionControl, "UInt")
IAudioSessionControl2 := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
DllCall(NumGet(NumGet(IAudioSessionControl2+0)+14*A_PtrSize), "UPtr", IAudioSessionControl2, "UIntP", ProcessId, "UInt")
If (PID == ProcessId)
{
ISimpleAudioVolume := ComObjQuery(IAudioSessionControl2, "{87CE5498-68D6-44E5-9215-6DA47EF883D8}")
DllCall(NumGet(NumGet(ISimpleAudioVolume+0)+3*A_PtrSize), "UPtr", ISimpleAudioVolume, "Float", MasterVolume/100.0, "UPtr", 0, "UInt")
ObjRelease(ISimpleAudioVolume)
}
ObjRelease(IAudioSessionControl2)
}
ObjRelease(IAudioSessionEnumerator)
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
请问下如何获取指定窗口当前音量呢? 想要弄个控制当前激活窗口音量的功能,但是这里Volume没设定初始值的话就无法实现
激活当前窗口音量直接设置100就行 这里是百分比 SetAppVolume(ProcessId, Volume := 100)
测试过程中发现该音量控制脚本对浏览器的音量控制好像没效果,但是对potplayer播放器音量可以有效控制,不知道是不是我哪一点没弄好
据我所知,浏览器声音播放不通过浏览器进程实现,所以没办法控制