From b91c73c5bba5fc2a0411c37c4fb74cce47d88389 Mon Sep 17 00:00:00 2001 From: bel Date: Tue, 12 Apr 2022 19:39:09 -0600 Subject: [PATCH] gr --- poc/py-ratio1024-log2/buttons.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/poc/py-ratio1024-log2/buttons.py b/poc/py-ratio1024-log2/buttons.py index c622236..44d38a3 100644 --- a/poc/py-ratio1024-log2/buttons.py +++ b/poc/py-ratio1024-log2/buttons.py @@ -18,6 +18,7 @@ def up(keycode): _display.sync() def __init_keys__(): + return [i for i in range(10, 20)] #1..0 import subprocess _p = subprocess.run( "xmodmap -pke".split(), @@ -26,12 +27,31 @@ def __init_keys__(): assert(_p.returncode == 0) stdout = _p.stdout result = [] - for line in stdout.split("\n".encode()): + allowed = ["F"+str(i) for i in range(13, 25)] + unassigned = [] + # already assigned + for line in stdout.split("\n".encode())[1:]: if line: words = line.split() key = int(words[1]) if len(words) < 4: + unassigned.append(key) + elif words[3].decode() in allowed: + allowed.remove(words[3].decode()) result.append(key) + # not assigned + for key in unassigned: + if not allowed: + break + word = allowed.pop() + if word: + assert(subprocess.run([ + "xmodmap", "-e", f"keycode {key} = {word}", + ]).returncode == 0) + result.append(key) + print("unassigned", unassigned) + print("allowed", allowed) + print("result", result) return result keys = __init_keys__()