101prairiedogs

Rapid Right Click Macro in Python

Jan 15th, 2024 (edited)
1,403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. '''
  2. Pressing and holding the X2 button rapidly clicks the right mouse button and the middle click.
  3. This macro was tested to work on a public Minecraft server, but could be caught by anti-cheating software.
  4. If your mouse lacks an x2 button, then rebinding to a different key is trivial.
  5.  
  6. Changing the line:
  7. 'if button == mouse.Button.x2:' to any mouse button of your choice will work just as well.
  8. '''
  9.  
  10. from pynput import mouse
  11. from pynput.mouse import Button, Controller
  12. from multiprocessing import Process, Event
  13. import sys
  14.  
  15. def listener(kill_event, flag_event):
  16.  
  17.     def on_click(x, y, button, pressed):
  18.         print(button, pressed)
  19.         if button == mouse.Button.x2:
  20.             if pressed:
  21.                 flag_event.set()
  22.             else:
  23.                 flag_event.clear()
  24.         if button == mouse.Button.x1:
  25.             # Stop the macro
  26.             print('Terminating...')
  27.             kill_event.set()
  28.             return False
  29.  
  30.     with mouse.Listener(on_click=on_click) as listener:
  31.         listener.join()
  32.  
  33. def task(kill_event, flag_event):
  34.     controller = Controller()
  35.     print('Listening...')
  36.     while True:
  37.         if kill_event.is_set():
  38.             sys.exit(0)
  39.         if flag_event.is_set():
  40.             controller.click(Button.right)
  41.             controller.click(Button.middle)
  42.  
  43. if __name__ == '__main__':
  44.     kill_event = Event()
  45.     flag_event = Event()
  46.  
  47.     listener_thread = Process(target=listener, args=(kill_event, flag_event))
  48.     task_thread = Process(target=task, args=(kill_event, flag_event))
  49.  
  50.     listener_thread.start()
  51.     task_thread.start()
  52.  
  53.     listener_thread.join()
  54.     task_thread.join()
  55.  
Advertisement
Add Comment
Please, Sign In to add comment