Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created January 31, 2021 13:18
Show Gist options
  • Save bananu7/005ec2ab756fdadd493d6cb06cf5eed0 to your computer and use it in GitHub Desktop.
Save bananu7/005ec2ab756fdadd493d6cb06cf5eed0 to your computer and use it in GitHub Desktop.
The fixed blackwidow.py script. Use Zadig and libusb

The following tutorial will help you setup a python script that will allow you to use the macro keys on your Razer Blackwidow keyboard with programs like AutoHotKey without the need for Razer Synapse.

Download and install python ( i used version 2.7.13 )

Download and install libusb-win32

Run the libusb-win32 "filter wizard"

select "Install a device filter" and click next

look for your Razer Blackwidow keyboard in the list of devices and click install

Download Pyusb

To install Pyusb open a command prompt window where "setup.py" is located and run the command "python setup.py install"

Download this Python script

Run the libusb-win32 "Test (win) Program" and open the Python script in a text editor

Make sure that the value of "VENDOR_ID" is the same as "idVendor" in the TestLibUsb window

Make sure that the value of "PRODUCT_ID" is the same as "idProduct" in the TestLibUsb window

Make sure that the value of "USB_INTERFACE" is the same as "bInterfaceNumber" in the TestLibUsb window

Save and run the Python script

The macro keys on your Blackwidow keyboard should now work without the need of razor synapse and should now correspond to the following keys:

m1 = f13

m2 = f14

m3 = f15

m4 = f16

m5 = f17

Fn = f24

The python script will need to be run every time you unplug / plugin your keyboard or reboot your PC; however the script can be made to run on startup. Steps 10 to 13 may need to be repeated if you change the usb port your keyboard is plugged in to.

#!/usr/bin/python
"""This is a patched version of Sergey's code form
https://superuser.com/a/474595/8647
It worked for my Razer BlackWidow 2013 Mechanical Gaming Keyboard
(Model Number: RZ03-0039).
"""
import usb
import sys
VENDOR_ID = 0x1532 # Razer
PRODUCT_ID = 0x010E # BlackWidow 2013 Mecanical Gaming Keyboard
USB_REQUEST_TYPE = 0x21 # Host To Device | Class | Interface
USB_REQUEST = 0x09 # SET_REPORT
USB_VALUE = 0x0300
USB_INDEX = 0x1
USB_INTERFACE = 0
USB_BUFFER = b"\x00\x00\x00\x00\x00\x02\x00\x04\x02\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00"
LOG = sys.stderr.write
class blackwidow(object):
kernel_driver_detached = False
def __init__(self):
self.device = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
if self.device is None:
raise ValueError("Device {}:{} not found\n".format(VENDOR_ID, PRODUCT_ID))
else:
LOG("Found device {}:{}\n".format(VENDOR_ID, PRODUCT_ID))
def __del__(self):
LOG("Releasing claimed interface\n")
usb.util.release_interface(self.device, USB_INTERFACE)
if self.kernel_driver_detached:
LOG("Reattaching the kernel driver\n")
self.device.attach_kernel_driver(USB_INTERFACE)
LOG("Done.\n")
def send(self, c):
def _send(msg):
result = 0
#try:
result = self.device.ctrl_transfer(USB_REQUEST_TYPE, USB_REQUEST, wValue=USB_VALUE, wIndex=USB_INDEX, data_or_wLength=USB_BUFFER)
#except:
# sys.stderr.write("Could not send data.\n")
if result == len(USB_BUFFER):
LOG("Data sent successfully.\n")
return result
if isinstance(c, list):
for i in c:
print(' >> {}\n'.format(i))
_send(i)
elif isinstance(c, str):
_send(c)
def main():
init_new = '0200 0403'
init_old = '0200 0402'
pulsate = '0303 0201 0402'
bright = '0303 0301 04ff'
normal = '0303 0301 04a8'
dim = '0303 0301 0454'
off = '0303 0301 0400'
bw = blackwidow()
bw.send(init_old)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment