Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,9 @@ def pairs_handler(dev, n):
# Pairs: J & K, U & I
keyboard.pairs = [{35, 36}, {20, 19}]

# Set a default light color and enable light on keypress
keyboard.set_default_color(r=0xFF, g=0, b=0xFF)
keyboard.light_on_press = True


keyboard.run()
31 changes: 30 additions & 1 deletion keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def __init__(self, keymap=(), pairs=(), verbose=True):
self.tap_delay = 500
self.fast_type_thresh = 200
self.pair_delay = 10
self.default_color = [0xFF, 0xFF, 0xFF]
self.light_on_press = False
self.RGB_OFF = 0
self.RGB_TAP = 1
self.RGB_FILL = 2
self.RGB_EMPTY = 3
self.rgb_mode = self.RGB_OFF

self._connection = ""

Expand All @@ -124,6 +131,9 @@ def __init__(self, keymap=(), pairs=(), verbose=True):
self.ble_hid = HID(ble_hid.devices)
self.usb_hid = HID(usb_hid.devices)

def set_default_color(self, r=0xFF, g=0xFF, b=0xFF):
self.default_color = [r, g, b]

def update_connection(self):
if usb_is_connected() and self.usb_status == 3:
conn = "USB"
Expand Down Expand Up @@ -398,10 +408,29 @@ def send_consumer(self, keycode):
except Exception as e:
print(e)

def update_rgb(self, event, pressed):
if self.rgb_mode == self.RGB_EMPTY and not self.backlight.dev.any():
self.backlight.on(*self.default_color)
return
key = event if pressed else (event & 0x7F)
if self.rgb_mode == self.RGB_EMPTY:
color = [0, 0, 0]
else:
color = self.default_color if pressed else [0, 0, 0]
if self.rgb_mode == self.RGB_TAP or ((self.rgb_mode == self.RGB_FILL or self.rgb_mode == self.RGB_EMPTY) and pressed):
self.backlight.pixel(key, *color)
if key == 56:
self.backlight.pixel(61, *color)
self.backlight.pixel(62, *color)
self.backlight.update()


def get(self):
key = self.matrix.get()
if key & 0x80 == 0:
pressed = key & 0x80 == 0
if pressed:
self.heatmap[key] += 1
self.update_rgb(key, pressed)
return key

def run(self):
Expand Down