Example#

  1. Change keyboard color when key is pressed

from random import randint

from pynput import keyboard

from logiled import LogitechLed, load_dll

load_dll()

logi_led = LogitechLed()


def on_press(key):
    r = randint(0, 100)
    g = randint(0, 100)
    b = randint(0, 100)
    logi_led.set_lighting(r, g, b)


def on_release(key):
    if key == keyboard.Key.esc:
        return False


# Collect events until released
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()


logi_led.shutdown()

Note

To exit program you need to press ESC key. You can change this key by anything you want. You can refer to keyboard.Key for special character or key.char for alphanumeric value.

Warning

This example will not work if you don’t have pynput installed. You can install it by pip install pynput