SomeChineseGuy

Untitled

Jun 5th, 2021 (edited)
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import evdev
  4. import psutil
  5. import os
  6. import subprocess
  7.  
  8. vendor = 9580
  9. product = 109
  10. version = 273
  11. name = "Pad"
  12.  
  13. bindings = {
  14.     256: "CTRL+Shift+H",
  15.     259: "CTRL+-",
  16.     260: "CTRL+Shift+=",
  17.     257: "B",
  18.     258: "Tab",
  19.     261: "E",
  20.     262: "CTRL+Z",
  21.     263: "CTRL+Shift+Z"
  22.         }
  23.  
  24. path = ""
  25.  
  26. ydotoold_found = False
  27. for proc in psutil.process_iter():
  28.     try:
  29.         if "ydotoold" in proc.name():
  30.             ydotoold_found = True
  31.             break
  32.     except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
  33.         pass
  34. if not ydotoold_found:
  35.     print("launching ydotoold")
  36.     subprocess.Popen("ydotoold", close_fds = True)
  37.     print("launched")
  38.  
  39. devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
  40.  
  41. for device in devices:
  42.     if name in device.name \
  43.             and device.info.vendor == vendor \
  44.             and device.info.product == product \
  45.             and device.info.version == version:
  46.                 path = device.path
  47.                 print(path)
  48.                 break
  49.  
  50. device = evdev.InputDevice(path)
  51. for event in device.read_loop():
  52.     if event.type == evdev.ecodes.EV_KEY:
  53.         print(event.code, event.value)
  54.         if (event.code in bindings.keys()):
  55.             press = "--down" if event.value == 1 else "--up"
  56.             subprocess.run(["ydotool", "key", press, bindings[event.code]])
Add Comment
Please, Sign In to add comment