Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Pressing and holding the X2 button rapidly clicks the right mouse button and the middle click.
- This macro was tested to work on a public Minecraft server, but could be caught by anti-cheating software.
- If your mouse lacks an x2 button, then rebinding to a different key is trivial.
- Changing the line:
- 'if button == mouse.Button.x2:' to any mouse button of your choice will work just as well.
- '''
- from pynput import mouse
- from pynput.mouse import Button, Controller
- from multiprocessing import Process, Event
- import sys
- def listener(kill_event, flag_event):
- def on_click(x, y, button, pressed):
- print(button, pressed)
- if button == mouse.Button.x2:
- if pressed:
- flag_event.set()
- else:
- flag_event.clear()
- if button == mouse.Button.x1:
- # Stop the macro
- print('Terminating...')
- kill_event.set()
- return False
- with mouse.Listener(on_click=on_click) as listener:
- listener.join()
- def task(kill_event, flag_event):
- controller = Controller()
- print('Listening...')
- while True:
- if kill_event.is_set():
- sys.exit(0)
- if flag_event.is_set():
- controller.click(Button.right)
- controller.click(Button.middle)
- if __name__ == '__main__':
- kill_event = Event()
- flag_event = Event()
- listener_thread = Process(target=listener, args=(kill_event, flag_event))
- task_thread = Process(target=task, args=(kill_event, flag_event))
- listener_thread.start()
- task_thread.start()
- listener_thread.join()
- task_thread.join()
Advertisement
Add Comment
Please, Sign In to add comment