我的搜索将我带到Pywin32,它应该能够静音/取消静音并检测其状态(在Windows 10上,使用Python 3+)。我找到了一种使用AutoHotkey脚本的方法,但是我正在寻找一种pythonic方法。

更具体地说,我对使用Windows GUI不感兴趣。 Pywin32使用Windows DLL进行工作。

到目前为止,我可以通过调用ahk脚本来做到这一点:

在python脚本中:

import subprocess
subprocess.call([ahkexe, ahkscript])

在AutoHotkey脚本中:
SoundGet, sound_mute, Master, mute
if sound_mute = On ; if the sound is muted
Send {Volume_Mute} ; press the "mute button" to unmute
SoundSet 30 ; set the sound level at 30

最佳答案

您可以通过paradoxis(https://github.com/Paradoxis/Windows-Sound-Manager)使用Windows声音管理器。

from sound import Sound
Sound.mute()

每次调用Sound.mute()都会打开或关闭静音。看一看main.py,看看如何使用setter和getter方法。

10-08 04:58