Rumyhub

The place where stuff Happens

Ubuntu: Fixing CM Storm Devastator keyboard backlit button.

Recently have bought an affordable and a very good keyboard and mouse set The CM Storm Devastator from Cooler Master, and the keyboard has a backlit keys, which are awesome for late night coding. On Windows the toggle switch is the scroll lock and work fines but recently have re-installed Ubuntu 14.10 and this functionality does not work out of the box like Windows.

I have installed to continue developing using NodeJS, C and C++ and even use it as my go to OS and wish to use this functionality. Fortunately the keyboard does not require any drivers and therefore their is no need to download packages from the site.

The keyboard can be easily lit by opening the terminal (CTRL + ALT + T) and typing

xset led on

And can also be switched off by typing

xset led of

Scripting

But although the keyboard has been lit, you have to type the above command every time you wish to toggle the backlit keys and this not what we want. So I have decided to write a simple bash script to operate the backlit the same way it is on Windows.

So lets start by getting the values for the led when the backlit is off and turning it on and then getting the led values again to be used later when creating the actual script. Start by creating  a script by opening your favourite text editor and enter the following. For this tutorial I'll be using GEDIT by any other will do.

#!/bin/bash
FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')

printf "$FLAGS""\n"
xset led on

FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')

printf "$FLAGS""\n"

When ready save the above script, I have saved it as keyboard-led.sh and placed within the root directory you can place wherever you like. When the saving is done type the following command to make the script executable.

chmod u+x keyboard-led.sh

Please note that sudo is needed if you are working in the root directory. To run the script just type the following command.

sudo /keyboard-led.sh

Now the keyboard should be on, (if the keyboard is off please review the script) and should have posted 2 values under each other, the first one 00000002 and the second one fffe7fe (may vary). Please take note of the last one which will be building the script on it. In case the keyboard's backlit was on during this process don't worry both values should be the same and the script should still work.

Toggling the Backlit

Reopen the script and replace the code with the following

#!/bin/bash
FLAGS=$(xset -q | awk 'NR==2' | awk '{ print $10 }')
if [ "$FLAGS" = ffffe7fe ]; then
    xset led off
else
    xset led on
fi

Now when running the script this will toggle the backlit of the keyboard on and off as you may not we used the second value in the if statement this was the OS will now whether the keyboard's backlit is on or off.

Create a Short Cut

Now if you manage to arrive here the hardest part if done and we just need to assign a short cut to the script using Ubuntu's GUI. Go to System Settings and to Keyboard and to Short Cuts and should arrive to the following screen.

Navigate to Custom Shortcuts and click on the plus symbol to add a new shortcut. Give the Name of ShortCut anything you wish example Keyboard lightOn and in the command section type /keyboard-led.sh and click apply.

Now click on the right of the newly created shortcut and click on scroll lock and if all went well you should end as follows.

Now you should be able to toggle On and Off the backlit of your keyboard.

blog comments powered by Disqus