Arachnophobia: Getting the macro keys on the Razer BlackWidow to work on linux

I bought the Razer BlackWidow for the hardware, not for Razer’s Synapse software or all the joys that it offers (Google suggest for searchers entering Razer Synapse? “Razer Synapse sucks”) Which meant that I was perfectly content not to use any of the special function keys on the keyboard. However the thought hit me that I had five Firefox profiles (yes, I prefer not to do my banking in the browser I watch smut in. There. Happy?) and there were five macro keys sitting in a row, not being used. 1+1=?

The keys do not at first appear to have a scancodes which means that they’re invisible to the kernel. This is bad. However back in 2012 somebody came up with a simple haskell/python script that fixed that. Later developments (read: Razer being pure evil Razer) has rendered this fix inoperable. The short of it is: If you bought your keyboard back in 2012 and hasn’t let Razer near it (i.e. hooked it up to Synapse 2.0 which apparently changes what codes the keyboard transmits) then everything is still fine. If not, you’re fucked.

Well, no actually. Superuser (user?) Sergey has  written a new fix. What it technically does is beyond me. Something about putting the keyboard into legacy mode which means that it transmits the codes that it originally did, before Synapse changed it. Or something.

I can’t say for sure that this will work for you and not actually brick the hardware. My keyboard was bought in May 2013 and bore the label ‘Model 2013’ on a tiny sticker. Seeing that Superuser user binary_runner reported succes with the exact same product id (see below) as me made me confident enough to try. YMMV. Here’s what I did:

  1. Copied the code from SuperUser into a python script, I named bwlegacy.py. I put the script in good old /usr/local/bin as per tradition.
  2. Ran ‘lsusb’ to find out the device id of the keyboard.
Bus 001 Device 004: ID 1532:011b Razer USA, Ltd 
Bus 001 Device 003: ID 1532:0037 Razer USA, Ltd

There were two Razer lines because I also had my mouse plugged in. What I need is the four digits/letters following the colon 011b (the upper line is the keyboard, the lower one is the mouse).

  1. Edited the script and inserted ‘011b’ as the value of the PRODUCT_ID variable.

3a. The script uses the python 3 usb module. So I installed the pyusb package from the AUR.

  1. Ran the script (as root) to make sure that it did what it was supposed to. It reported success and I tested that the keys now output keycodes using xev. They did.
  2. Wrote a systemd service unit so that I could run the script on startup (a quick test showed that the effects weren’t permanent). I put the service file in /etc/systemd/system. Here’s the contents of blackwidow.service:
[Unit]
Description=Enable BlackWidow Macro Keys

[Service]
ExecStart=/usr/local/bin/bwlegacy.py

[Install]
WantedBy=multi-user.target
  1. Enabled the service with
systemctl enable blackwidow.service
  1. Rebooted and tested that the effect was there. It was. Huzzah.

A final word of caution. Seeing as Synapse not just acts as a driver and some windows applications but can permanently change the way the keyboard works, I’d suggest never letting it near your keyboard again. There seems to be a genuine risk that the silent upgrading Synapse will one day activate some other state change and so render this fix null and void. I have previously argued that Synapse wasn’t so bad as all that and that might still stand if you’re a Windows-only user. But if there is a risk that it might ruin things for me on the linux side, I’ll be the first to grab the pitchfork and the wooden stake.

EDIT: For people on Upstart rather than systemd here’s an Upstart task job (an Upstart service that’s meant to start and the end as opposed to a constantly running daemon-like job):

# bwlegacy
#
# This service runs a python script to enable razer black widow keyboard macro keys

description "Enable black widow macro keys"
start on runlevel [2345]
task
console log
script
     echo "Enabling Black Widow macro keys..." 
     exec /usr/local/bin/bwlegacy.py
     #initctl emit -n myEvent
end script

Copy-and-paste the contents into a bwlegacy.conf file in /etc/init and reboot.

Photo by Scott Kinmartin

Leave a Reply

Your email address will not be published. Required fields are marked *