有些窗口希望它静音或者减少音量,可以用下面这个函数
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播放器音量可以有效控制,不知道是不是我哪一点没弄好
据我所知,浏览器声音播放不通过浏览器进程实现,所以没办法控制