47 lines
992 B
Python
47 lines
992 B
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__():
|
|
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__()
|
|
|
|
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()
|