add buttons.py, un-ignore testdata

master
bel 2022-04-12 07:43:59 -06:00
parent 302c70800e
commit fda468227e
3 changed files with 48 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
**/*.sw* **/*.sw*
**/testdata
**/__pycache__ **/__pycache__

View File

@ -0,0 +1,36 @@
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__():
import subprocess
_p = subprocess.run(
"xmodmap -pke".split(),
capture_output=True,
)
assert(_p.returncode == 0)
stdout = _p.stdout
result = []
for line in stdout.split("\n".encode()):
if line:
words = line.split()
key = int(words[1])
if len(words) < 4:
result.append(key)
return result
keys = __init_keys__()

View File

@ -2,6 +2,8 @@ import argparse
import os import os
from time import sleep from time import sleep
import buttons
def main(): def main():
args = get_args() args = get_args()
buckets = {} buckets = {}
@ -14,16 +16,16 @@ def main():
continue continue
key = line.strip("/").split()[0] key = line.strip("/").split()[0]
if not key in buckets: if not key in buckets:
buckets[key] = False buckets[key] = [False, len(buckets)]
buckets[key] = False if line[0] == "/" else float(line.split()[-1]) buckets[key][0] = False if line[0] == "/" else float(line.split()[-1])
result = sorted([ for key in bucket:
(int(100*buckets[k]), k) for k in buckets if buckets[k] keycode = buttons.keys[bucket[key][1]]
], reverse=True) if bucket[key][0]:
print("[", print("down", key, button[key])
" ".join([ buttons.down(keycode)
"{}={:2}".format(i[1], i[0]) for i in result else:
]), print("up", key, button[key])
"]") buttons.up(keycode)
def get_args(): def get_args():
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()