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.
71 lines
2.3 KiB
71 lines
2.3 KiB
5 years ago
|
#! /bin/python3
|
||
|
|
||
|
import openrazer.client
|
||
|
import json
|
||
|
from pathlib import Path
|
||
|
from pynput import keyboard
|
||
|
|
||
|
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,kbd_rows):
|
||
|
for column in range(0, kbd_columns):
|
||
|
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()
|
||
|
|
||
|
kbd_rows, kbd_columns = kbd.fx.advanced.rows, kbd.fx.advanced.cols
|
||
|
|
||
|
|
||
|
last_key_pressed = None
|
||
|
def on_press(key):
|
||
|
global last_key_pressed
|
||
|
last_key_pressed = key
|
||
|
return False
|
||
|
|
||
|
def get_key():
|
||
|
with keyboard.Listener(on_press=on_press) as listener:
|
||
|
listener.join()
|
||
|
|
||
|
def set_key_columns(keymap, column_range, prefix=""):
|
||
|
for row in range(0,kbd_rows):
|
||
|
for column in column_range:
|
||
|
clear_all(kbd)
|
||
|
kbd.fx.advanced.matrix[row,column] = [255, 255, 255]
|
||
|
kbd.fx.advanced.draw()
|
||
|
get_key()
|
||
|
print('{} was pressed'.format(last_key_pressed))
|
||
|
keymap[prefix + str(last_key_pressed)] = row * kbd_columns + column
|
||
|
|
||
|
def iter_keys():
|
||
|
keymap = dict()
|
||
|
print("Make sure caps lock and numpad are disabled, if not, do it now and restart the script")
|
||
|
print("This script will iterate over all keys, row by row. When a key lights up white, press it, and use the mouse to cancel any F-key effects. First, we'll skip the numpad. If no key lights up, press the bottom-right most key, excluding the numpad().")
|
||
|
set_key_columns(keymap, range(0,18))
|
||
|
print("Now we'll iterate over the numpad, if no key lights up, press the bottom right key(enter)")
|
||
|
set_key_columns(keymap, range(18,kbd_columns), "num_")
|
||
|
return keymap
|
||
|
|
||
|
def write_keymap_file(dictionary):
|
||
|
keymap_json = json.dumps(keymap)
|
||
|
path = Path.home() / '.config/openrazer_scripter/keymap.json'
|
||
|
Path(path.parent).mkdir(parents=True, exist_ok=True)
|
||
|
with open(path,'w') as keymap_file:
|
||
|
keymap_file.write(keymap_json)
|
||
|
|
||
|
keymap = iter_keys()
|
||
|
write_keymap_file(keymap)
|
||
|
print('Saved keymap to file (.config/openrazer_scripter/keymap.json)')
|