queueFunc.py 764 B

12345678910111213141516171819202122232425262728293031
  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. print(jsonObject)
  8. print(time.time())
  9. if jsonObject['function'] == 0:
  10. on_click(jsonObject['x'], jsonObject['y'], jsonObject['button'])
  11. else:
  12. on_scroll(jsonObject['x'], jsonObject['y'], jsonObject['dx'], jsonObject['dy'])
  13. def on_click(x, y, button):
  14. mouseController.position = (x, y)
  15. if 'left' in button:
  16. print('w')
  17. mouseController.click(Button.left, 1)
  18. else:
  19. print('2')
  20. mouseController.click(Button.right, 1)
  21. def on_scroll(x, y, dx, dy):
  22. mouseController.position = (x, y)
  23. mouseController.scroll(dx, dy)