Burathar
4 years ago
commit
0b7f31735e
1 changed files with 58 additions and 0 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
#! /bin/python3 |
||||
import sys |
||||
import time |
||||
import signal |
||||
from openrazer_command import Keyboard, Color |
||||
from evdev import InputDevice, ecodes |
||||
|
||||
class GracefulKiller: |
||||
kill_now = False |
||||
def __init__(self): |
||||
signal.signal(signal.SIGINT, self.exit_gracefully) |
||||
signal.signal(signal.SIGTERM, self.exit_gracefully) |
||||
|
||||
def exit_gracefully(self,signum, frame): |
||||
self.kill_now = True |
||||
|
||||
keyboard = Keyboard() |
||||
|
||||
if not keyboard.found_keyboard(): |
||||
print("No keyboard was found") |
||||
exit() |
||||
|
||||
def redraw(capslock_enabled, numlock_enabled): |
||||
keyboard.set_static(Color(0,100,0)) |
||||
|
||||
if capslock_enabled: |
||||
keyboard.set_keys(Color(255,255,255), 'caps_lock') |
||||
|
||||
if numlock_enabled: |
||||
keyboard.set_keys(Color(255,255,255), 'num_lock') |
||||
|
||||
keyboard.draw() |
||||
|
||||
def daemon(): |
||||
device = InputDevice('/dev/input/by-id/usb-Razer_Razer_BlackWidow_Chroma_V2-event-kbd') |
||||
capslock_enabled = False |
||||
numlock_enabled = False |
||||
killer = GracefulKiller() |
||||
|
||||
while not killer.kill_now: |
||||
update = False |
||||
|
||||
capslock_previous = capslock_enabled |
||||
numlock_previous = numlock_enabled |
||||
leds = device.leds() |
||||
capslock_enabled = 1 in leds |
||||
numlock_enabled = 0 in leds |
||||
if capslock_previous != capslock_enabled or numlock_previous != numlock_enabled: |
||||
update = True |
||||
|
||||
if update: |
||||
redraw(capslock_enabled, numlock_enabled) |
||||
|
||||
time.sleep(.1) |
||||
sys.exit(0) |
||||
|
||||
if __name__=='__main__': |
||||
daemon() |
Loading…
Reference in new issue