#! /bin/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(). " )
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 ( )
print ( ' Saved keymap to file (.config/openrazer_scripter/keymap.json) ' )