add buttons.py, un-ignore testdata
parent
302c70800e
commit
fda468227e
|
|
@ -1,3 +1,2 @@
|
|||
**/*.sw*
|
||||
**/testdata
|
||||
**/__pycache__
|
||||
|
|
|
|||
|
|
@ -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__()
|
||||
|
|
@ -2,6 +2,8 @@ import argparse
|
|||
import os
|
||||
from time import sleep
|
||||
|
||||
import buttons
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
buckets = {}
|
||||
|
|
@ -14,16 +16,16 @@ def main():
|
|||
continue
|
||||
key = line.strip("/").split()[0]
|
||||
if not key in buckets:
|
||||
buckets[key] = False
|
||||
buckets[key] = False if line[0] == "/" else float(line.split()[-1])
|
||||
result = sorted([
|
||||
(int(100*buckets[k]), k) for k in buckets if buckets[k]
|
||||
], reverse=True)
|
||||
print("[",
|
||||
" ".join([
|
||||
"{}={:2}".format(i[1], i[0]) for i in result
|
||||
]),
|
||||
"]")
|
||||
buckets[key] = [False, len(buckets)]
|
||||
buckets[key][0] = False if line[0] == "/" else float(line.split()[-1])
|
||||
for key in bucket:
|
||||
keycode = buttons.keys[bucket[key][1]]
|
||||
if bucket[key][0]:
|
||||
print("down", key, button[key])
|
||||
buttons.down(keycode)
|
||||
else:
|
||||
print("up", key, button[key])
|
||||
buttons.up(keycode)
|
||||
|
||||
def get_args():
|
||||
ap = argparse.ArgumentParser()
|
||||
|
|
|
|||
Loading…
Reference in New Issue