mouse_emulate.py 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python3
  2. import os
  3. import sys
  4. import dbus
  5. import dbus.service
  6. import dbus.mainloop.glib
  7. DBUS_OBJ_BTK_NAME = 'org.thanhle.btkbservice'
  8. DBUS_OBJ_BTK_PATH = '/org/thanhle/btkbservice'
  9. class MouseClient():
  10. def __init__(self):
  11. super().__init__()
  12. self.state = [0, 0, 0, 0]
  13. self.bus = dbus.SystemBus()
  14. self.btkservice = self.bus.get_object(DBUS_OBJ_BTK_NAME, DBUS_OBJ_BTK_PATH)
  15. self.iface = dbus.Interface(self.btkservice, DBUS_OBJ_BTK_NAME)
  16. def send_current(self):
  17. try:
  18. self.iface.send_mouse(0, bytes(self.state))
  19. except OSError as err:
  20. error(err)
  21. if __name__ == "__main__":
  22. if (len(sys.argv) < 5):
  23. print("Usage: mouse_emulate [button_num dx dy dz]")
  24. exit()
  25. client = MouseClient()
  26. client.state[0] = int(sys.argv[1])
  27. client.state[1] = int(sys.argv[2])
  28. client.state[2] = int(sys.argv[3])
  29. client.state[3] = int(sys.argv[4])
  30. print("state:", client.state)
  31. client.send_current()