Advertisement
Guest User

AutoMoveMouse

a guest
Apr 10th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. import sys
  2. import time
  3.  
  4. from Quartz.CoreGraphics import CGEventCreateMouseEvent
  5. from Quartz.CoreGraphics import CGEventPost
  6. from Quartz.CoreGraphics import kCGEventMouseMoved
  7. from Quartz.CoreGraphics import kCGEventLeftMouseDown
  8. from Quartz.CoreGraphics import kCGEventLeftMouseUp
  9. from Quartz.CoreGraphics import kCGMouseButtonLeft
  10. from Quartz.CoreGraphics import kCGHIDEventTap
  11.  
  12.  
  13. def mouseEvent(event_type, pos_x, pos_y):
  14.     event = CGEventCreateMouseEvent(None, event_type, (pos_x, pos_y), kCGMouseButtonLeft)
  15.     CGEventPost(kCGHIDEventTap, event)
  16.  
  17.  
  18. def mousemove(pos_x, pos_y):
  19.     mouseEvent(kCGEventMouseMoved, pos_x, pos_y)
  20.  
  21.  
  22. def mouseclick(pos_x, pos_y):
  23.     # mouseEvent(kCGEventMouseMoved, posx,posy)
  24.     mouseEvent(kCGEventLeftMouseDown, pos_x, pos_y)
  25.     mouseEvent(kCGEventLeftMouseUp, pos_x, pos_y)
  26.  
  27.  
  28. def main():
  29.     if len(sys.argv) < 4:
  30.         print('Usage:\n    python main.py <center_x> <center_y> <duration>')
  31.         sys.exit(1)
  32.  
  33.     center_x = int(sys.argv[1])
  34.     center_y = int(sys.argv[2])
  35.     duration = int(sys.argv[3])
  36.  
  37.     side_size = 500
  38.     step = 5
  39.     add = lambda axis, step: axis + step
  40.     sub = lambda axis, step: axis - step
  41.  
  42.     if center_x < 0 or center_y < 0 or duration < 1:
  43.         print('center_x and center_y must be more than {}, duration must be more 1'.format(side_size))
  44.         sys.exit(1)
  45.  
  46.     x = center_x - side_size
  47.     y = center_y - side_size
  48.     end_time = time.time() + duration
  49.  
  50.     while time.time() < end_time:
  51.         for x_delta_func, y_delta_func in (
  52.             (add, add),
  53.             (add, sub),
  54.             (sub, sub),
  55.             (sub, add)
  56.         ):
  57.             for idx in range(0, side_size, step):
  58.                 x = x_delta_func(x, step)
  59.                 y = y_delta_func(y, step)
  60.                 mousemove(x, y)
  61.                 time.sleep(0.01)
  62.  
  63.         print("Cycle done in {} {}".format(x, y))
  64.  
  65.     print("Done")
  66.  
  67.  
  68. if __name__ == '__main__':
  69.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement