How do I change the system volume in windows using python, with just using the python standard library? I know how to change the system volume by pressing the volume keys:
from ctypes import WinDLL
user32 = WinDLL("user32")
# Turns volume up:
for _ in range(50):
user32.keybd_event(0xAF, 0, 0, 0)
user32.keybd_event(0xAF, 0, 2, 0)
# Turns volume down:
for _ in range(50):
user32.keybd_event(0xAE, 0, 0, 0)
user32.keybd_event(0xAE, 0, 2, 0)
But how to I set the volume to a certain value, without using any extra python packages? I'd also like a way to get the current volume.
Edit: The suggested question does not answer my question because all the answers to that question either don't work on windows, or they use extra python packages, or they just press the volume keys, and I want way of setting the volume to a certain value and a way of getting the current volume.