My Bluetooth headphones' (connected using a USB dongle) play/pause button doesn't work with Windows 10 (the volume changers work just fine), so I tried to remap the key, it gets, to the media play/pause button.
First I tried with AHKHID, and used the examples to find out what HID device is connected. That just showed the keyboard and mouse. So I looked more into Bluetooth devices and wrote a program to get the available Bluetooth services running on the headphones. The 3 services it could find was SPP, HSP and HFP. From these, SPP looked like the most promising, as Wikipedia states
It emulates a serial cable to provide a simple substitute for existing RS-232, including the familiar control signals. It is the basis for DUN, FAX, HSP and AVRCP.
I knew that AVRCP should be the one the controls are sent with, so this must be the one the play/pause signal is coming from. I looked at the serial COM ports available on my computer and found that it uses COM3 for incoming and COM4 for outgoing communication with the headphones.
Now this is where I got stuck. I tried to connect to the SPP service running on the headphones programatically, which worked (didn't throw any errors), but the input data event didn't fire and the stream read timed out.
I also tried to inspect the serial data with Serial Port Monitor (the trial version), but it doesn't show anything except when I click open or close, it shows a bunch of setup messages.
What can the problem be? Is Windows using it and so it prevents other programs from accessing it (or empties the stream before others could see it)? Or am I doing something completely wrong?
Meanwhile I installed the native Spotify app for Windows and it detects the button presses just fine. As this was my main goal with this research, I won't look more into it, but it would be interesting to know where it gets the button presses from and why it doesn't work for other apps.