Skip to content

Instantly share code, notes, and snippets.

@jkazimierczak
Created July 11, 2021 18:36
Show Gist options
  • Save jkazimierczak/be0d6e1d8aba0e33adaa01415a8910ce to your computer and use it in GitHub Desktop.
Save jkazimierczak/be0d6e1d8aba0e33adaa01415a8910ce to your computer and use it in GitHub Desktop.
Controlling Windows Media with pywin32
from win32api import keybd_event
from win32con import VK_MEDIA_PLAY_PAUSE, VK_MEDIA_PREV_TRACK, VK_MEDIA_NEXT_TRACK, VK_VOLUME_UP, VK_VOLUME_DOWN, VK_VOLUME_MUTE
class MediaControl:
@staticmethod
def play_pause():
keybd_event(VK_MEDIA_PLAY_PAUSE, 0)
@staticmethod
def next_track():
keybd_event(VK_MEDIA_NEXT_TRACK, 0)
@staticmethod
def prev_track():
keybd_event(VK_MEDIA_PREV_TRACK, 0)
@staticmethod
def volume_down():
keybd_event(VK_VOLUME_DOWN, 0)
@staticmethod
def volume_up():
keybd_event(VK_VOLUME_UP, 0)
@staticmethod
def volume_mute():
keybd_event(VK_VOLUME_MUTE, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment