from pynput.mouse import Controller, Button import json import time mouseController = Controller() def handleMessage(properties, body): jsonObject = json.loads(body) if jsonObject['function'] == 0: on_click(jsonObject['x'], jsonObject['y'], jsonObject['button']) else: on_scroll(jsonObject['x'], jsonObject['y'], jsonObject['dx'], jsonObject['dy']) def on_click(x, y, button): mouseController.position = (x, y) if 'left' in button: print('w') mouseController.click(Button.left, 1) time.sleep(0.1) else: print('2') mouseController.click(Button.right, 1) time.sleep(0.1) def on_scroll(x, y, dx, dy): mouseController.position = (x, y) mouseController.scroll(dx, dy)