buzl.uk


Want extra keys? Use your earbuds

Published on

#python #key #earbud

Have you ever wanted to set random actions to your keyboard keys but realized that you use them all for other purposes, like writing? Well, with this little trick, you can use your earbuds (in an unconventional way) to run custom actions on your computer.

Earbuds

I have a pair of Sony earbuds that have touch controls on both sides. On my phone, I can use them to control the media playback, and some other actions that I completely forgot about. However, those actions are not customizable, at least not on my computer. So by default, we have 3 gestures: single tap, double tap, and triple tap. These gestures are assigned to the media playback controls as play/pause, next, and previous respectively. But that’s not what we want. You’re with me, right? Let’s get started.

Media Session API

I tried to listen for Bluetooth events on my computer but it was way too complicated. Then I remembered about the Media Session API, which is a web API to control the media playback on your computer. You can set some metadata (which shows up on your control center) and even listeners for various events like play, pause, next, and previous. You see where I’m going with this. We’ll just put together a simple web page with a dummy audio element and listen for the events and send them over to our Python script to run functions as background tasks.

I hope you’re not bored with Quart yet because that’s what you’re getting from me again.

Earbuds

The Prototype

There is a hidden audio element below the button, which gets played when you click the button. By clicking on the gestures, you can select one of the custom actions to assign it to that gesture.

Earbuds

And when you toggle the switch, the page starts listening for the events without messing up with other media playing on your computer. Now’s the time to ask, what can you do with this? Well, I asked the same question to mysql (little typo there, but I’m keeping it because it’s funny) and came up with these terrible ideas:

Some of these are already implemented in the code, but I’m sure you can come up with better ideas. You can find the code here. I hope this little thing keeps you entertained for a while. It kept me entertained while I was trying to open up terminals after terminals with my earbuds. Have fun!

kaangiray26
P.S.

so you're telling me that I can get 3 extra keys if I give away 3 of my keys? Sounds right to me.

Webmentions