Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import time
- from Quartz.CoreGraphics import CGEventCreateMouseEvent
- from Quartz.CoreGraphics import CGEventPost
- from Quartz.CoreGraphics import kCGEventMouseMoved
- from Quartz.CoreGraphics import kCGEventLeftMouseDown
- from Quartz.CoreGraphics import kCGEventLeftMouseUp
- from Quartz.CoreGraphics import kCGMouseButtonLeft
- from Quartz.CoreGraphics import kCGHIDEventTap
- def mouseEvent(event_type, pos_x, pos_y):
- event = CGEventCreateMouseEvent(None, event_type, (pos_x, pos_y), kCGMouseButtonLeft)
- CGEventPost(kCGHIDEventTap, event)
- def mousemove(pos_x, pos_y):
- mouseEvent(kCGEventMouseMoved, pos_x, pos_y)
- def mouseclick(pos_x, pos_y):
- # mouseEvent(kCGEventMouseMoved, posx,posy)
- mouseEvent(kCGEventLeftMouseDown, pos_x, pos_y)
- mouseEvent(kCGEventLeftMouseUp, pos_x, pos_y)
- def main():
- if len(sys.argv) < 4:
- print('Usage:\n python main.py <center_x> <center_y> <duration>')
- sys.exit(1)
- center_x = int(sys.argv[1])
- center_y = int(sys.argv[2])
- duration = int(sys.argv[3])
- side_size = 500
- step = 5
- add = lambda axis, step: axis + step
- sub = lambda axis, step: axis - step
- if center_x < 0 or center_y < 0 or duration < 1:
- print('center_x and center_y must be more than {}, duration must be more 1'.format(side_size))
- sys.exit(1)
- x = center_x - side_size
- y = center_y - side_size
- end_time = time.time() + duration
- while time.time() < end_time:
- for x_delta_func, y_delta_func in (
- (add, add),
- (add, sub),
- (sub, sub),
- (sub, add)
- ):
- for idx in range(0, side_size, step):
- x = x_delta_func(x, step)
- y = y_delta_func(y, step)
- mousemove(x, y)
- time.sleep(0.01)
- print("Cycle done in {} {}".format(x, y))
- print("Done")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement