TimeWaster's Place

The “Logitech G213 Prodigy Gaming Keyboard” is a pretty good rubber dome keyboard with the usual multimedia keys plus the gaming button which turns of some annoying keys while gaming. It has no unneeded nick-nack, the illumination is bright (enough) and the keys have a good feel while typing.

The problem comes with the illuminated keys, the standard color effect used by the keyboard is a color cycle animation which is terribly distracting while typing. What i planned when i bought this keyboard was to set the illumination under Windows and then use the keyboard under Linux, but since Logitech considers the G213 an “entry level” keyboard (Even though it is pretty expensive) it cannot save the set illumination as a profile inside the keyboard like the G9 mouse or highest priced G keyboards for instance can. This means you have to run the Gaming Software under Windows all the time for the keyboard to behave as expected.

I had now two possible ways to go, either send the G213 back or get it to at least set the color correctly under Linux.

There are a couple of old projects doing that for older keyboards and other Logitech equipment under Linux, but not for the G213. It seems that with every new keyboard at least parts of the commands used change so you cannot use the old projects (Like Gnome15 , G19Linux and others based on that code) with any equipment that is not specifically included in the projects. Another problem for me is that these projects seem to be mostly abandoned (even though the software still should work) and they are either written in C++ or are too complicated for me to adapt them to my needs.

You can see where this is heading… i started to write my own script to be able to set the colors on my keyboard, called “G213Colors”.

As a starting point i used USBPcap to capture the raw USB data sent to the keyboard from the Logitech Gaming Software and opened the resulting files with Wireshark . It took me a long time to understand that multiple lines in Wireshark belong to the same data package since i did not find a nice introduction into the Wireshark interface, but in the end i found a 20-byte data string sent to the keyboard that was fortunately not encrypted, obfuscated or contained any incrementing numbers or something. This string contained the color i was setting in the expected format (RGB) which was very good news to me since now i only had to test-send this string to my keyboard to see if it would be working.

Since i wanted to send raw data over USB i could not use Bash scripts, it had to be a real programming (scripting) language, so i decided to use Python since it has a large array of plugins for all kinds of needs and is easy to learn if you already know another language and is preinstalled on most Linux distributions.

In Python there is PyUSB to achieve what i wanted even though i have to say PyUSB is a bit too low-level for my taste but there is no alternative for it.

Under Linux there is usually a kernel driver attached to the keyboard’s USB interface(s) as soon as you plug it in (Which makes sense since the kernel is handling all keyboards) which prevents any data from being sent to the keyboard, so you have to detach (and re-attach later) this driver with PyUSB.

After a lot of trial and error due to unread of confusing documentation i managed to send the command and my keyboard changed from that annoying color changing cycle to a nice white color. Success!

The command structure is rather simple, no matter if you just want to set one color or want to activate a color effect, it is always a 20-byte string containing a 3-byte RGB color value or sometimes also a 2-byte integer which controls the speed. This example sets the color Purple (Hex color value ff00ff) with the command 11ff0c3a0001ff00ff0200000000000000000000 (In a hex representation), notice the color value at byte position 7.

What i could not determine is why the Gaming Software is always sending the string 11ff0c0a00000000000000000000000000000000 in advance of changing a color, in my tests it made no difference at all if i also send it or not, when someone has an idea please leave a comment.

Since i found no software at all able to control the G213 keyboard i decided to publish my script under MIT license on GitHub, where you will find instruction on how to “install” and use this script:

Download G213Colors on GitHub

It can then be called from cron and other parts of Linux as well as being linked from the menu or integrated into your own scripts.

I hope it is as useful to you as it is to me, have fun!

Posted by TimeWaster Programming , Tools color , G213 , gaming , illumination , key color , key illumination , keyboard , keys , linux , Logitech , Logitech Gaming , Logitech Gaming Software , python , reverse engineering 16 Comments

Tad says: 28.12.2016 (December 28) at 18:34 How difficult would it be to convert this to a windows batch (or Powershell?) script to run at startup? All I want is to use the G213 keyboard with one solid back-light color, and get rid of the bloated Logitech Gaming Software (which causes the Surface Pro to think a keyboard and a mouse are connected even when they are not). Reply TimeWaster says: 28.12.2016 (December 28) at 18:44 Hi, it shouldn’t be too hard, you would have to install python and PyUSB on windows, also you would need to remove lines 59 to 62 and 67 to 69 since there are no kernel drivers on windows. that should be it… Reply Tad says: 02.01.2017 (January 02) at 17:56 Ideally I would like a batch file (or executable) that runs native on Windows and does not require installing any other support library that is not built into Windows 7 and newer. If you would do this and leave the finished product and source code in the public domain, I will send you a $200 contribution (e.g. two hundred US dollars via PayPal) once it is done and working reliably. If you are not interested, I would open the same offer to anyone interested–limited to the first individual with success as described but not past a deadline of May 1st 2017. Reply

How difficult would it be to convert this to a windows batch (or Powershell?) script to run at startup? All I want is to use the G213 keyboard with one solid back-light color, and get rid of the bloated Logitech Gaming Software (which causes the Surface Pro to think a keyboard and a mouse are connected even when they are not).

TimeWaster says: 28.12.2016 (December 28) at 18:44 Hi, it shouldn’t be too hard, you would have to install python and PyUSB on windows, also you would need to remove lines 59 to 62 and 67 to 69 since there are no kernel drivers on windows. that should be it… Reply Tad says: 02.01.2017 (January 02) at 17:56 Ideally I would like a batch file (or executable) that runs native on Windows and does not require installing any other support library that is not built into Windows 7 and newer. If you would do this and leave the finished product and source code in the public domain, I will send you a $200 contribution (e.g. two hundred US dollars via PayPal) once it is done and working reliably. If you are not interested, I would open the same offer to anyone interested–limited to the first individual with success as described but not past a deadline of May 1st 2017. Reply

Hi, it shouldn’t be too hard, you would have to install python and PyUSB on windows, also you would need to remove lines 59 to 62 and 67 to 69 since there are no kernel drivers on windows. that should be it…

Tad says: 02.01.2017 (January 02) at 17:56 Ideally I would like a batch file (or executable) that runs native on Windows and does not require installing any other support library that is not built into Windows 7 and newer. If you would do this and leave the finished product and source code in the public domain, I will send you a $200 contribution (e.g. two hundred US dollars via PayPal) once it is done and working reliably. If you are not interested, I would open the same offer to anyone interested–limited to the first individual with success as described but not past a deadline of May 1st 2017. Reply

Ideally I would like a batch file (or executable) that runs native on Windows and does not require installing any other support library that is not built into Windows 7 and newer. If you would do this and leave the finished product and source code in the public domain, I will send you a $200 contribution (e.g. two hundred US dollars via PayPal) once it is done and working reliably. If you are not interested, I would open the same offer to anyone interested–limited to the first individual with success as described but not past a deadline of May 1st 2017.

Kee-Yeong Tan says: 10.03.2017 (March 10) at 10:27 You’re a life saver! (well, or at least an “eye saver” lol) I will attempt the same packet sniffing on my G403 mouse, inspired by your script. Though admittedly pulsating lights on a mouse is significantly less annoying than the keyboard. Reply TimeWaster says: 10.03.2017 (March 10) at 10:36 you’re welcome ^^ about packet sniffing: the most difficult part was to read the structure of the usb data in Wireshark, i found the representation extremely confusing. Reply

You’re a life saver! (well, or at least an “eye saver” lol)

I will attempt the same packet sniffing on my G403 mouse, inspired by your script. Though admittedly pulsating lights on a mouse is significantly less annoying than the keyboard.

TimeWaster says: 10.03.2017 (March 10) at 10:36 you’re welcome ^^ about packet sniffing: the most difficult part was to read the structure of the usb data in Wireshark, i found the representation extremely confusing. Reply

you’re welcome ^^

about packet sniffing: the most difficult part was to read the structure of the usb data in Wireshark, i found the representation extremely confusing.

Erik says: 17.03.2017 (March 17) at 15:30 This is really helpful! I’m very grateful! Reply

This is really helpful! I’m very grateful!

Ian Pulsford says: 29.07.2017 (July 29) at 12:52 Hey thanks for posting this. I bought one of these keyboards the other day and I assumed I could set it in windows and it would remember its colour settings. I’m using FreeBSD and I am able to use the native usbconfig utility with the following parameters (in case any other FreeBSD users find this): usbconfig -u N -a M do_request 0x21 0x09 0x0211 0x0001 0x14 0x11 0xff 0x0c 0x3a 0x00 0x01 0xRR 0xGG 0xBB 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (substituting N and M for the device and, RR, GG and BB for the colour as appropriate) Basically the same as device.ctrl_transfer in your sendData method with an extra parameter stating the length of the data following (0x14). I may even try my hand at a C utility just to learn a bit more about libusb. Reply TimeWaster says: 29.07.2017 (July 29) at 14:28 hi Ian, no, the keyboard itself doesn’t save anything… i was as surprised as you, since my G9 for instance remembers all settings. Your solution looks nice! And if you have new stuff you can learn always go for it! Reply

Hey thanks for posting this. I bought one of these keyboards the other day and I assumed I could set it in windows and it would remember its colour settings. I’m using FreeBSD and I am able to use the native usbconfig utility with the following parameters (in case any other FreeBSD users find this): usbconfig -u N -a M do_request 0x21 0x09 0x0211 0x0001 0x14 0x11 0xff 0x0c 0x3a 0x00 0x01 0xRR 0xGG 0xBB 0x02 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (substituting N and M for the device and, RR, GG and BB for the colour as appropriate)

Basically the same as device.ctrl_transfer in your sendData method with an extra parameter stating the length of the data following (0x14). I may even try my hand at a C utility just to learn a bit more about libusb.

TimeWaster says: 29.07.2017 (July 29) at 14:28 hi Ian, no, the keyboard itself doesn’t save anything… i was as surprised as you, since my G9 for instance remembers all settings. Your solution looks nice! And if you have new stuff you can learn always go for it! Reply

hi Ian, no, the keyboard itself doesn’t save anything… i was as surprised as you, since my G9 for instance remembers all settings. Your solution looks nice! And if you have new stuff you can learn always go for it!

Superm8y says: 27.10.2017 (October 27) at 17:54 Thankyou, you’re amazing Reply

Thankyou, you’re amazing

Christian says: 05.12.2017 (December 05) at 21:47 Hi, thank you very much for this software, it works great for my G213. However, the keyboard multimedia keys seem to not be producing any key codes for me, did you by chance get these to work? (Volume and playback control) Reply TimeWaster says: 05.12.2017 (December 05) at 22:02 they work fine on my side, maybe try to unplug the keyboard, maybe something got tangled up and the driver was not correctly reattached. if it happens again let me know. Reply

thank you very much for this software, it works great for my G213. However, the keyboard multimedia keys seem to not be producing any key codes for me, did you by chance get these to work? (Volume and playback control)

TimeWaster says: 05.12.2017 (December 05) at 22:02 they work fine on my side, maybe try to unplug the keyboard, maybe something got tangled up and the driver was not correctly reattached. if it happens again let me know. Reply

they work fine on my side, maybe try to unplug the keyboard, maybe something got tangled up and the driver was not correctly reattached. if it happens again let me know.

Kelvin Costner says: 07.06.2018 (June 07) at 17:22 Do you know you can hold the light key and press the number row keys to change effects right? The 0 key can make all keyboard same color. Press it multiple times to change the color to white… Only inconvenience is having to do it every boot. Reply TimeWaster says: 02.07.2018 (July 02) at 17:36 I didn’t know, thanks! Reply Mario says: 10.02.2019 (February 10) at 09:38 LOL oh man this is what I was looking for XDD so why is it everyone asking for a script if this just does it!! I was thinking of modding it so didnt mater what os you were using it with. Reply

Do you know you can hold the light key and press the number row keys to change effects right? The 0 key can make all keyboard same color. Press it multiple times to change the color to white… Only inconvenience is having to do it every boot.

TimeWaster says: 02.07.2018 (July 02) at 17:36 I didn’t know, thanks! Reply

I didn’t know, thanks!

Mario says: 10.02.2019 (February 10) at 09:38 LOL oh man this is what I was looking for XDD so why is it everyone asking for a script if this just does it!! I was thinking of modding it so didnt mater what os you were using it with. Reply

LOL oh man this is what I was looking for XDD so why is it everyone asking for a script if this just does it!! I was thinking of modding it so didnt mater what os you were using it with.

bder says: 28.04.2019 (April 28) at 15:13 Hello i have the keyboard too and it didn’t work! phytho just says “invalid syntax” what can i do? Reply TimeWaster says: 28.04.2019 (April 28) at 18:08 do you use linux and python 2 or 3? Reply

Hello i have the keyboard too and it didn’t work! phytho just says “invalid syntax” what can i do?

TimeWaster says: 28.04.2019 (April 28) at 18:08 do you use linux and python 2 or 3? Reply

do you use linux and python 2 or 3?

Your e-mail address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Save my name, e-mail, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed .

GitHub: Chamfers for OpenSCAD

GitHub: Snake for MicroView

GitHub: TV Screen for MicroView

Thingiverse: Chamfers for OpenSCAD

Thingiverse: Pulley for Geeetech Prusa i3 B+C Idler Belt Tensioner

Devilmastah's Blog

© 2019 TimeWaster's Place