Logitech G815 Shortcut Helper
I wrote a small shortcut helper in GoLang that helps me to remember the most useful shortcuts for IntelliJ based products tested with Rider and GoLand and a QWERTZ keyboard.
Intro
I recently bought a Logitech G815 which turned out to be a great decision for multiple reasons. The obvious one being that it's a great keyboard ✨. The other one is that I found out Logitech provides an SDK for the keyboard => 👌.
RGB Keys
The keyboard supports RGB background lighting for each key. There are plenty of integrated functions such as a color wave which looks great🌟. The keyboard is made for gaming purposes and yes it does integrate with a lot of games but I didn't try any myself🙈.
SDK
The Logitech SDK can be found on this website: https://www.logitechg.com/en-us/innovation/developer-lab.html.
I was particularly interested in the LED Illumination SDK.
The SKD is written in C++ and provides the .lib, .h, .dll, and some examples and is windows only.
Integration with GO
I'm currently learning GoLang and I wanted to program this in go and not in C++ or C#.
Calling native C++ functions from GO
I found a great way to call native C++ functions from Go using the sys
module.
Original repo: https://github.com/golang/go/wiki/WindowsDLLs
type LogiKeyboard struct {
dll *windows.LazyDLL
ledInit *windows.LazyProc
// ...
}
func Create() *LogiKeyboard {
p := new(LogiKeyboard)
// initialization of the dll
p.dll = windows.NewLazyDLL("LogitechLedEnginesWrapper.dll")
// assign the function
p.ledInit = p.dll.NewProc("LogiLedInit")
//...
return p
}
// wrapper for the init function
func (v LogiKeyboard) Init() {
ret, _, _ := v.ledInit.Call()
if ret != 1 {
log.Fatal("Already initialized")
}
}
Additionally, I had to translate the .h file in go syntax. This helps to have all the constants (like defines) in one place and reduce code duplication. Here is the file.
Integration with Windows
I needed a slim and easy way to catch Windows keystrokes. Turns out there is a great module for that as well: github.com/moutend/go-hook.
main.go:
if err := run(shortcuts); err != nil {
log.Fatal(err)
}
func run(shortcuts []Shortcuts.Shortcut) error {
// Buffer size is depends on your need. The 100 is placeholder value.
keyboardChan := make(chan types.KeyboardEvent, 100)
if err := keyboard.Install(nil, keyboardChan); err != nil {
return err
}
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
for {
select {
case <-time.After(5 * time.Minute):
fmt.Println("Received timeout signal")
return nil
case <-signalChan:
fmt.Println("Received shutdown signal")
return nil
case k := <-keyboardChan:
// check if shortcut modifiers are pressed and set RGB color
}
continue
}
}
Those few lines of code are everything you need to create a keylogger in go. Isn't that crazy?
Shortcuts
Shortcuts can be modified in main.go
:
var shortcuts = []Shortcuts.Shortcut{
// if the left shift key is presed:
// F6 will start blinking red
// F9 will change the color to blue
Shortcuts.CreateWithKey([]types.VKCode{types.VK_LSHIFT}, []Shortcuts.ShortcutKey{
Shortcuts.CreateKeyColorEffect(LogiKeyboardTypes.F6, 100, 0, 0, Shortcuts.Blinking),
Shortcuts.CreateKeyColor(LogiKeyboardTypes.F9, 0, 0, 100),
}),
//...
}
Integration with Logitech GHub
The keyboard has five G keys and each key can be assigned with a different task. One task is to launch an application => great :). The downside of this function is that an application can be started but not stopped. I wanted to start and stop the shortcut helper with the same key just like a toggle.
As always there is a workaround in PowerShell😂:
Set-Location -Path C:\Projects\LogitechKeyboardLED
$ProcessActive = (Get-Process logitechKeyboardLed -ErrorAction SilentlyContinue).Id
if($null -eq $ProcessActive)
{
Start-Process ./logitechKeyboardLed.exe -NoNewWindow
}
else
{
Stop-Process $ProcessActive
}
Configure the G key using the Launch Application
option:
Shortcuthelper in action
Github Repo
klyse / LogitechKeyboardLED
Logitech G815 / G915 LED control written in GO
Logitech G815 ⌨️ Rider and GoLand Shortcut helper
This is a little shortcut helper written in GO G
keys. Once started the process profiles every keystroke made on the keyboard. If a certain combination ex. SHIFT+CTRL
is pressed the most important shortcuts for Rider / GoLang are visualized on the keyboard using the RGB key background lightning
Here's a quick example (sorry for the bad quality, the keys are shining bright and clear in reality
Here's another one:
How to install 💻
- Clone the repo
- Build the source code
go build -o LogitechKeyboardLED.exe ./
(win only) - Navigate to the
GHub
- Add a new launch command with the following params:
The script checks the state of the process and starts it if the process is stopped, and stops it if the process is running. This way…
Thanks for reading :)
Top comments (6)
There are an abundance of custom and premade keyboards that run the completely open source QMK firmware. At least from what I gathered from this article, you could do everything you did here (and all of the other QMK features) in an OS agnostic manner. There's no reason to log keys in the OS in order to drive the hardware (leds); you can do that directly on the hardware itself.
I wasn't aware of the QMK firmware. But if this works with the Logitech G815 keyboard this could really be a great alternative. Thanks for the comment :)
This is amazing. I do not like the windows only part tho...
Thanks :) Yes I know, I don't like windows only either... The Logitech SDK is windows only.
Now I want to buy keyboard with API that would work on Mac 😂
This post motivated me to create something similar for my asus rog laptop which has each key RGB 😀