Example #1
0
 def move_mouse(self):
     x = random.randint(0, self.width)
     y = random.randint(0, self.height)
     #create the event
     move = CG.CGEventCreateMouseEvent(None, CG.kCGEventMouseMoved,
                                       CG.CGPointMake(x, y),
                                       CG.kCGMouseButtonLeft)
     #send the event
     CG.CGEventPost(CG.kCGHIDEventTap, move)
Example #2
0
    def click_mouse(self):
        point = CG.CGPointMake(self.width / 2, 250)
        # Move mouse to top-middle position.
        move = CG.CGEventCreateMouseEvent(None, CG.kCGEventMouseMoved, point,
                                          CG.kCGMouseButtonLeft)
        # Mouse down.
        down = CG.CGEventCreateMouseEvent(NULL, CG.kCGEventLeftMouseDown,
                                          point, CG.kCGMouseButtonLeft)
        # Mouse up.
        up = CG.CGEventCreateMouseEvent(NULL, CG.kCGEventLeftMouseUp, point,
                                        CG.kCGMouseButtonLeft)

        #send the events
        CG.CGEventPost(CG.kCGHIDEventTap, move)
        CG.CGEventPost(CG.kCGHIDEventTap, down)
        time.sleep(0.05)
        CG.CGEventPost(CG.kCGHIDEventTap, up)