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.
50 lines
1.7 KiB
50 lines
1.7 KiB
5 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
|
from .keyboard import Keyboard
|
||
|
from .keymap import Keymap
|
||
|
from .color import Color
|
||
|
import openrazer.client
|
||
|
|
||
|
from pynput import keyboard as keyboardnput
|
||
|
|
||
|
keyboard = Keyboard(no_keymap=True)
|
||
|
|
||
|
if not keyboard.found_keyboard():
|
||
|
print("No keyboard was found")
|
||
|
exit()
|
||
|
|
||
|
last_key_pressed = None
|
||
|
def on_press(key):
|
||
|
global last_key_pressed
|
||
|
last_key_pressed = key
|
||
|
return False
|
||
|
|
||
|
def get_key():
|
||
|
with keyboardnput.Listener(on_press=on_press) as listener:
|
||
|
listener.join()
|
||
|
|
||
|
def set_key_columns(keymap, column_range, prefix=""):
|
||
|
for row in range(0, 6):
|
||
|
for column in column_range:
|
||
|
keyboard.clear()
|
||
|
keyboard.set_key(row,column, Color(255, 255, 255))
|
||
|
keyboard.draw()
|
||
|
get_key()
|
||
|
print('{} was pressed'.format(last_key_pressed))
|
||
|
keymap[prefix + str(last_key_pressed)] = row * 22 + 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(right-arrow).")
|
||
|
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, 22), "num_")
|
||
|
return keymap
|
||
|
|
||
|
|
||
|
keymap = Keymap()
|
||
|
keymap.set_keys(iter_keys())
|
||
|
keymap.write_keymap_file(keyboard.keyboard_name)
|
||
|
print('Saved keymap to file (.config/openrazer_scripter/keymap.json)')
|