How to make Python (3.7) manipulate any media player currently working on Windows?
I want to get functionality similar to media keys on keyboard, for example:
To clarify: I don't want Python to virtually press actual media keys on keyboard. I would like to get the functionality of such keys so it might work even without keyboard connected to PC.
The easiest solution is to use win32api.keybd_event
from pywin32.
For example, install pywin32:
pip install pywin32
And try play/pause - should work without keyboard:
import win32api
from win32con import VK_MEDIA_PLAY_PAUSE, KEYEVENTF_EXTENDEDKEY
win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_EXTENDEDKEY, 0)
Virtual-Key Codes: here and here.
NOTE:
At this link about keybd_event function, you can see message: "Note This function has been superseded. Use SendInput instead".
So if you want/need to use SendInput, you probably need to use ctypes
. I suggest you to check the example here. I've tried that code too and it works. If you need any further help, let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With