Logitech G19 Scripts

On this page you can find scripts for the Logitech G19 keyboard developed by me. I’m a fan of Lua and I like colorful LEDs so after having setup my G19 the first thing I did was writing a script that would fade the backlight color randomly when I press one of the G keys.

The Logitech G19 software allows the user to create a script for a profile. I prefer modularization over dumping everything on one place so I developed two modules you can find in my core. They are able to easily load an external Lua script file into the profile’s script. If you want to use my color fading script you’ll have to set it up. Descriptions on how to use it and set it up are in the respective section.

I’m not much into licensing so I just released my scripts under the GPL. Forbidding actions on a freely and publicly released piece of data won’t hinder people from doing with it what they want to. I’d just ask you to pin a link to this page nearby, if you make one of the scripts available somewhere. And don’t sell it for money.



Download Core

The core contains two modules. The ScriptManager and the EventManager.


The ScriptManager is for loading scripts from the core directory.
This is no primitive task as the core directory probably differs from the execution directory.

ScriptManager.loadScript(fileName) will load the script with the given filename, whereas the file path is considered to be relative to the core script directory.
The function passes the loaded script’s directory as first program argument so it may load additional files from there.
Initially this was also planned to enable a script reading and writing files from and to it’s directory, but unfortunately the Logitech G19 script environment disables io and os functions. dofile and loadfile work nevertheless though.


The Logitech G19 script API provides one function to handle incoming events like a pressed G key. The EventManager can be used to add an arbitrary amount of handler functions for specific or general events.

EventManager.addEventHandler(event, argument, handler) will add a new event handler function to the existing pool.
event specifies the event’s name, e.g. ‘G_KEY_PRESSED’, argument sets a filter for the argument provided with the event, e.g. 7 in combination with the mentioned event example to set a handler for the G7 key, and the last argument, handler is the actual handler function.
If all arguments are specified, the given handler will only be called, if the incoming event matches the constraints. argument may be left out to make a handler for the named event, regardless of the respective attribute. In addition, event may be left out as well to create a handler like the OnEvent function itself.
Any event triggering OnEvent will cause the EventHandler to invoke all handler functions assigned to the event, passing the event’s name as first and the argument as second argument.

That said, an existing OnEvent function may easily be made compatible to the core scripts by renaming it, e.g. to GlobalEventHandler, and adding it as global event handler. For the mentioned example this could be done by calling EventManager.addEventHandler(GlobalEventHandler).


  • find a directory where you want to place the scripts in
  • extract the script files from the archive to this directory
  • add the following lines to your profile script

Random Color Fader

Download Color Fader (requires the Core)

The color fader script binds (up to) three keys.
One key for enabling and displaying information, if the script is already enabled, one key for disabling and one for fading to the next random color.

What the script basically does is fading your backlight from one color to another, whereas the new color is chosen randomly.
The script also fades in on loading the profile and out on unloading it. It preserves the backlight color when changing the mode and also when switching it off and on.
Due to a lack of I/O functionality in the Logitech G19 script environment the script is unable to save and load colors between different profiles.

If you happen to get a backlight color you really like you can find out the color code by pressing the enable key while the color script is enabled. The color information will be displayed on your display then. If it doesn’t work right away, give it some further tries. The display sometimes doesn’t want to react.


  • extract the color_fader directory to your core script directory
  • add the following lines below the code that loads ScriptManager and eventManager
    ColorFader.initialize(KEY_CF_ENABLE, KEY_CF_DISABLE, KEY_CF_NEXT);
  • replace the KEY_CF_* placeholders with the respective G key numbers to bind or set the variables (e.g. ColorFader.initialize(5, 11, 12) to use G5 to enable, G11 to disable and G12 to fade to the next color)
  • in your Key Profiler, set the keys you specified in the initialization function as script keys


April 27, 2014 (1.0.0 -> 1.0.1)
  • updated SetBacklightColor call to work with the new Logitech gaming software

2 thoughts on “Logitech G19 Scripts”

  1. Hello,

    at first i want to say, great script. It looks realy awesome how it fades.

    I would have one Question.
    Is there a posibility to make it change the colors from itself?
    If so, due to my lack of LUA scripting i would apprechiate if you could give a litte how to or an 2nd version from the fading script.


    1. Hello Arkadius,

      sorry that my answer comes so late – I just got the impression that noone actually reads or comments my blog, so I lost motivation for maintaining it. But now I’m here to answer.

      As I got the idea of writing such a script, I initially wanted it to fade automatically as well. I don’t know if I can remember all the reasons that hindered me to do so, but one was probably that Lua, without extensions (which aren’t addable to the Logitech Lua interpreter as far as I know), doesn’t allow me to make a second thread nor to make a non-blocking timer, i.e. one that doesn’t block the whole script.
      So the only non-hacky way to realize such an automatic fader would be making a script that actually runs in an endless loop forever (from boot to shutdown) while being busy, i.e. not allowing other scripts to run. I think I tested such a script back then and ran into further problems, where other important things were blocked as well.
      I’d have to retry it though to find out if there is a good way to do it.

      So one would, in general, make a script like:
      while (true)
      Sleep(60000); -- wait a minute; you could also make a random time here

      Let me know if you find out something cool.


Leave a Reply to Neosublimation Cancel reply

Blogging since 1337 BC

%d bloggers like this: