You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.7 KiB

#! /bin/python3
import openrazer.client
import json
from pathlib import Path
import math
def get_keyboard():
devman = openrazer.client.DeviceManager()
for device in devman.devices:
if (device.name == "Razer BlackWidow Chroma V2"):
return device
return None
def clear_all(kbd):
# Set full keyboard to green
for row in range(0, 6):
for column in range(0, 22):
kbd.fx.advanced.matrix[row,column] = [0, 0, 0]
kbd = get_keyboard()
if (kbd == None):
print("No Razer device with devicename 'Razer Blackwidow Chroma V2' found.")
exit()
def read_keymap_file():
path = Path.home() / '.config/openrazer_scripter/keymap.json'
keymap = None
with open(path,'r') as keymap_file:
keymap = json.load(keymap_file)
return keymap
def get_row_column(index):
row = math.floor(index / 22)
column = index % 22
return row, column
def set_all_white(kbd, keymap):
clear_all(kbd)
for key, value in keymap.items():
position = get_row_column(value)
kbd.fx.advanced.matrix[position[0], position[1]] = [255,255,255]
kbd.fx.advanced.draw()
def sort_dict(dictionary):
return {k: v for k, v in sorted(dictionary.items(), key=lambda item: item[1])}
def iter_keys(kbd, keymap):
keymap = sort_dict(keymap)
for key, value in keymap.items():
clear_all(kbd)
position = get_row_column(value)
print(f'key: {key}')
kbd.fx.advanced.matrix[position[0], position[1]] = [255,255,255]
kbd.fx.advanced.draw()
input()
keymap = read_keymap_file()
while True:
set_all_white(kbd, keymap)
input("Press Enter to continue...")
iter_keys(kbd, keymap)