I've long wanted to learn morse code, and years ago I started to look around for a nice, affordable iambic key.

Turned out this was an oxymoron - these things are expensive af! So I put my new-found hobby to rest...

Then yesterday I was given a bunch of YubiKeys destined for the waste-bin at work. A YubiKey, for those of you who don't know, is a physical 2FA device that you plug into your USB port and gently caress to authenticate yourself (e.g. when logging into a computer).

I have no particular use for their original purpose, but something with those capacitive touch sensors reminded me of morse code for some reason.

The idea came when I noticed you can put a static password on it, so that the device types it out every time you touch it. I put '.' as password on one unit and '-' on another.

This worked very well, apart from the fact that after registering a touch, the device doesn't listen for another one for a couple seconds. This would limit the WPM (Words Per Minute) to something ridiculously low, and after a bit of research I found that this behaviour is hard-coded in the firmware. Which is obviously pretty hard to fiddle with, given the nature of the device.

After some more research though, I found that a value called "touch_level" can be read from the device. This turned out to be an integer ranging from around 500 (not touched) to 3-4000 (touched). Not only that, but there is even a nifty Python library, making it incredibly easy to use this value in your own application!

With this information, it didn't take long to cobble together a Python script that lets me use two YubiKeys as a morse keyboard :-)