67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
from Xlib.display import Display
|
|
from Xlib.ext.xtest import fake_input
|
|
from Xlib import X
|
|
from os import environ
|
|
|
|
_display = Display(environ['DISPLAY'])
|
|
|
|
def tap(keycode):
|
|
down(keycode)
|
|
up(keycode)
|
|
|
|
def down(keycode):
|
|
fake_input(_display, X.KeyPress, keycode)
|
|
_display.sync()
|
|
|
|
def up(keycode):
|
|
fake_input(_display, X.KeyRelease, keycode)
|
|
_display.sync()
|
|
|
|
def __init_keys__():
|
|
return [i for i in range(10, 20)] #1..0
|
|
import subprocess
|
|
_p = subprocess.run(
|
|
"xmodmap -pke".split(),
|
|
capture_output=True,
|
|
)
|
|
assert(_p.returncode == 0)
|
|
stdout = _p.stdout
|
|
result = []
|
|
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__()
|
|
|
|
if __name__ == "__main__":
|
|
import time
|
|
for key in keys:
|
|
print("pushing", key, "in...")
|
|
for i in range(3):
|
|
print("", 3-i, "...")
|
|
time.sleep(1)
|
|
tap(53)
|
|
exit()
|