Skip to content

Using the keyboard driver

Luke Horwell edited this page Apr 22, 2016 · 4 revisions

Keyboard Driver

Inside the folder of the device binded to the driver there will be some of the following files (some should disappear if they are not supported by the keyboard when we get multi-keyboard support). For all the example commands shown you need to be root to run them.

Example of the device path:

/sys/bus/hid/drivers/razerkbd/<DEVICE ID>/

device_type - Device Type (Read only)

This file doesn't accept being written to but when it is read it will output a string identifying the type of device it is. I though using this would be easier than remembering the USB vender/product IDs.

Example command

$ cat device_type
Razer BlackWidow Chroma

macro_keys - Enabling Macro Keys (Write only)

This file literally doesn't care what is written to it. Once it has been written to, it will enable macro keys on the keyboard so that they generate keycodes.

M1 generates keycode 191 and M5 generates 195.

When read this file will always output 0.

Example command

$ echo -n "1" > macro_keys

mode_breath - Breathing effect mode (Write only)

This is a complicated one. Breathing mode has 3 modes of operation. Mode 1 fading in and out using a single colour. Mode 2 is fading in and out between two colours. Finally mode 3 is fading in and out between random colours (there's a pattern, its not random ;) ).

If 1 byte is written to it, random mode will be activated. (Technically any number of bytes as long as its not 3 or 6).

If 3 bytes are written to it, single colour mode will be activated and the 3 bytes will be interpreted as RGB.

If 6 bytes are written to it, dual colour mode will be activated and the 3 bytes will be interpreted as RGB colour 1 and the last 3 bytes will be RGB colour 2.

Example commands

$ echo -n "1" > mode_breath                              # Random Mode
$ echo -n -e "\xFF\x00\x00" > mode_breath                # Single mode (red)
$ echo -n -e "\xFF\x00\x00\x00\x00\xFF" > mode_breath    # Dual mode (red & blue)

mode_custom (Write only)

Activates custom mode on the keyboard / sort of refreshes the keyboard when the colours of the rows have been changed.

This is normally called after writing to set_key_row

Example command

$ echo -n "1" > set_key_row

mode_game - Game mode (Write only)

The reason the Chroma and Ultimate 2013 keyboards have 2 Keyboard interfaces is that one is used solely for game mode. The 2nd keyboard device is just like a normal keyboard but its missing the super key, bit of an over-the-top way to disable the super key in my opinion.

Writing a 1 will enable game mode, writing a 0 will disable it.

Example commands:

$ echo -n "1" > mode_game
$ echo -n "0" > mode_game

mode_none - No effect mode (Write only)

This sets the Chroma to no effect mode. This file doesn't care what is written to it, just that something is written.

Example command:

$ echo -n "1" > mode_none

mode_reactive - Reactive effect mode

This sets the keyboard into the reactive effect mode where you last few key presses illuminate for a period of time.

This file accepts 1 byte which denoted the speed. Must be in the range of 1-3, 1 being short, 3 being long. Then 3 bytes meaning RGB.

Example commands

$ echo -n -e "\x01\x00\xFF\xFF" > mode_reactive
$ echo -n -e "\x03\xFF\x00\xFF" > mode_reactive

First commands is reactive mode where the keys don't illuminate for that long with a cyan colour. The second is purple with the longest illumination time.

mode_spectrum - Spectrum effect mode (Write only)

This mode the keyboard will cycle though the colour spectrum. Doesn't care what's written to it.

Example command

$ echo -n "1" > mode_spectrum

mode_pulsate - Pulsing effect mode (Write only)

This is only available for the Razer BlackWidow Ultimate 2013. This mode just fades in and out.

Example command

$ echo -n "1" > mode_pulsate

mode_static - Static effect mode (Write only)

This mode the keyboard shows a single colour. It accepts 3 bytes representing RGB.

Note: if used on the Razer BlackWidow Ultimate, the files doesn't care what is written to it, it will just set the keyboard to static mode.

Example command

$ echo -n -e "\xFF\x00\xFF" > mode_static

mode_wave - Wave effect mode (Write only)

This mode sends colour waves across the keyboard. It accepts either 1 or 2 representing the direction of the wave Right or Left.

Example commands

$ echo -n "1" > mode_wave
$ echo -n "2" > mode_wave

reset - Reset keyboard (Write only)

This command seems to reset the keyboard. It is called a fair bit by the official Razer driver. This file also doesn't care whats written to it.

Example command

$ echo -n "1" > reset

set_brightness - Sets keyboard brightness (Write only)

This accepts integers from 0-255. Not sure of the keyboards actual brightness resolution but it seems pretty good. 0 for off and 255 for max brightness.

Example commands

$ echo -n "0" > set_brightness
$ echo -n "255" > set_brightness

set_logo - Sets the on/off state of the Blade Stealth lid logo (Write only)

This accepts either a 0 or 1 to disable or enable the LED. No brightness control is available.

Example commands

$ echo -n "0" > set_logo
$ echo -n "1" > set_logo

set_key_row - Sets colour of keyboard row (Write only)

This command sets a row on the keyboard. It accepts 22 RGB values and a row index. The first byte should be the row index (0-5) and then 22 RGB values.

You can concatenate these byte strings as long as the total length is a multiple of 23, the driver will run each section like if it were called multiple times.

Example command

dev_path="/sys/bus/hid/drivers/razerkbd/0003:1532:0203.0050"
for row_index in 0 1 2 3 4 5
do
    echo -n -e "\x0$row_index\x0\x0\x0\xFF\xFF\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0" > $dev_path/set_key_row
done
echo -n "1" > $dev_path/mode_custom

Set dev_path to be the path to your active device. This "should" set the Escape, Backtick, Tab, CapsLk, Shift and left Ctrl key to yellow.

temp_clear_row - Clears a row on the keyboard (Write only)

Clears a row on the keyboard. Takes in 0-5

Example command

$ echo -n "0" > temp_clear_row

get_serial - Gets the serial number from the device

Gets the serial number from the device, usually 2 numbers then 13 digits in my experience.

Example command

$ cat get_serial
XX1111111111111