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.
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
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