queueFunc.py 766 B

123456789101112131415161718192021222324252627282930
  1. from pynput.mouse import Controller, Button
  2. import json
  3. import time
  4. mouseController = Controller()
  5. def handleMessage(properties, body):
  6. jsonObject = json.loads(body)
  7. if jsonObject['function'] == 0:
  8. on_click(jsonObject['x'], jsonObject['y'], jsonObject['button'])
  9. else:
  10. on_scroll(jsonObject['x'], jsonObject['y'], jsonObject['dx'], jsonObject['dy'])
  11. def on_click(x, y, button):
  12. mouseController.position = (x, y)
  13. if 'left' in button:
  14. print('w')
  15. mouseController.click(Button.left, 1)
  16. time.sleep(0.1)
  17. else:
  18. print('2')
  19. mouseController.click(Button.right, 1)
  20. time.sleep(0.1)
  21. def on_scroll(x, y, dx, dy):
  22. mouseController.position = (x, y)
  23. mouseController.scroll(dx, dy)