Exemplo n.º 1
0
def relativeMotion(x, y, mouseDelay=None):
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 2
0
def absoluteMotionWithTrajectory(source_x, source_y, dest_x, dest_y, mouseDelay=None, check=True):
    """
    Synthetize mouse absolute motion with trajectory. The 'trajectory' means that the whole motion
    is divided into several atomic movements which are synthetized separately.
    """
    if check:
        checkCoordinates(source_x, source_y)
        checkCoordinates(dest_x, dest_y)
    logger.log("Mouse absolute motion with trajectory to (%s,%s)" % (dest_x, dest_y))

    dx = float(dest_x - source_x)
    dy = float(dest_y - source_y)
    max_len = max(abs(dx), abs(dy))
    if max_len == 0:
        # actually, no motion requested
        return
    dx /= max_len
    dy /= max_len
    act_x = float(source_x)
    act_y = float(source_y)

    for _ in range(0, int(max_len)):
        act_x += dx
        act_y += dy
        if mouseDelay:
            doDelay(mouseDelay)
        registry.generateMouseEvent(int(act_x), int(act_y), name='abs')

    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 3
0
    def mouse_event(x, y, button, eventType):
        """
        > Description
            Generates a mouse press or release event on a specific pixel on the screen

        > Parameters
            x (int): the x coordinate where the event will be generated
            y (int): the y coordinate where the event will be generated
            button (str): A string indicating which mouse button to press/release. One of 'left', 'right' or 'middle'
            eventType (str): A string indicating the event type. One of 'press' or 'release'

        > Returns
            None

        > Example
            # this example could demonstrate a drag and drop of a file

            # press the left mouse button at 100, 100
            Macro.mouse_event(100, 100, 'left', 'press')
            # move the cursor to 400, 400
            Macro.move_cursor_to(400, 400)
            # then, release the mouse
            Macro.mouse_event(400, 400, 'left', 'press')
        """
        buttonToNo = {'left': 1, 'right': 2, 'middle': 3}
        controller.generateMouseEvent(
            x, y, 'b' + str(buttonToNo[button]) +
            ('p' if eventType == 'press' else 'r'))
Exemplo n.º 4
0
    def mouse_event(x, y, button, eventType):
        """
        > Description
            Generates a mouse press or release event on a specific pixel on the screen

        > Parameters
            x (int): the x coordinate where the event will be generated
            y (int): the y coordinate where the event will be generated
            button (str): A string indicating which mouse button to press/release. One of 'left', 'right' or 'middle'
            eventType (str): A string indicating the event type. One of 'press' or 'release'

        > Returns
            None

        > Example
            # this example could demonstrate a drag and drop of a file

            # press the left mouse button at 100, 100
            Macro.mouse_event(100, 100, 'left', 'press')
            # move the cursor to 400, 400
            Macro.move_cursor_to(400, 400)
            # then, release the mouse
            Macro.mouse_event(400, 400, 'left', 'press')
        """
        buttonToNo = {'left':1, 'right':2, 'middle':3 }
        controller.generateMouseEvent(x, y, 'b' + str(buttonToNo[button]) + ('p' if eventType == 'press' else 'r'))
Exemplo n.º 5
0
def release(x, y, button=1, check=True):
    """
    Synthesize a mouse button release at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s release at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sr' % button)
    doDelay()
Exemplo n.º 6
0
def click(x, y, button=1, check=True):
    """
    Synthesize a mouse button click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s click at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sc' % button)
    doDelay(config.actionDelay)
Exemplo n.º 7
0
def doubleClick(x, y, button=1, check=True):
    """
    Synthesize a mouse button double-click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s doubleclick at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sd' % button)
    doDelay()
Exemplo n.º 8
0
def doubleClick(x, y, button=1, check=True):
    """
    Synthesize a mouse button double-click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s doubleclick at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sd' % button)
    doDelay()
Exemplo n.º 9
0
def click(x, y, button=1, check=True):
    """
    Synthesize a mouse button click at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s click at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sc' % button)
    doDelay(config.actionDelay)
Exemplo n.º 10
0
def release(x, y, button=1, check=True):
    """
    Synthesize a mouse button release at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s release at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, 'b%sr' % button)
    doDelay()
Exemplo n.º 11
0
def press(x, y, button=1, check=True):
    """
    Synthesize a mouse button press at (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse button %s press at (%s,%s)" % (button, x, y))
    registry.generateMouseEvent(x, y, name='b%sp' % button)
    doDelay()
Exemplo n.º 12
0
def relativeMotion(x, y, mouseDelay=None):
    """
    Synthetize a relative motion from actual position.
    Note: Does not check if the end coordinates are positive.
    """
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 13
0
def relativeMotion(x, y, mouseDelay=None):
    """
    Synthetize a relative motion from actual position.
    Note: Does not check if the end coordinates are positive.
    """
    logger.log("Mouse relative motion of (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='rel')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 14
0
def absoluteMotion(x, y, mouseDelay=None, check=True):
    """
    Synthesize mouse absolute motion to (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse absolute motion to (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'abs')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 15
0
def absoluteMotion(x, y, mouseDelay=None, check=True):
    """
    Synthesize mouse absolute motion to (x,y)
    """
    if check:
        checkCoordinates(x, y)
    logger.log("Mouse absolute motion to (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, name='abs')
    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 16
0
    def move_cursor_to(x, y):
        """
        > Description
            Moves the cursor to the x, y coordinates

        > Parameters
            x (int): the x coordinate to move the cursor to
            y (int): the y coordinate to move the cursor to

        > Returns
            None

        > Example
            # move the cursor to 100, 100
            Macro.move_cursor_to(100, 100)
        """
        controller.generateMouseEvent(x, y, MOUSE_ABS)
Exemplo n.º 17
0
    def move_cursor_to(x, y):
        """
        > Description
            Moves the cursor to the x, y coordinates

        > Parameters
            x (int): the x coordinate to move the cursor to
            y (int): the y coordinate to move the cursor to

        > Returns
            None

        > Example
            # move the cursor to 100, 100
            Macro.move_cursor_to(100, 100)
        """
        controller.generateMouseEvent(x, y, MOUSE_ABS)
Exemplo n.º 18
0
    def right_click_to(x, y):
        """
        > Description
            Right clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to right click to
            y (int): the y coordinate to right click to

        > Returns
            None

        > Example
            # right click to 100, 100
            Macro.right_click_to(100, 100)
        """
        if (x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b3c')
Exemplo n.º 19
0
    def middle_click_to(x, y):
        """
        > Description
            Middle clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to middle click to
            y (int): the y coordinate to middle click to

        > Returns
            None

        > Example
            # middle click to 100, 100
            Macro.middle_click_to(100, 100)
        """
        if (x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b2c')
Exemplo n.º 20
0
    def right_click_to(x, y):
        """
        > Description
            Right clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to right click to
            y (int): the y coordinate to right click to

        > Returns
            None

        > Example
            # right click to 100, 100
            Macro.right_click_to(100, 100)
        """
        if(x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b3c')
Exemplo n.º 21
0
    def middle_click_to(x, y):
        """
        > Description
            Middle clicks the mouse at x, y

        > Parameters
            x (int): the x coordinate to middle click to
            y (int): the y coordinate to middle click to

        > Returns
            None

        > Example
            # middle click to 100, 100
            Macro.middle_click_to(100, 100)
        """
        if(x >= 0 and y >= 0):
            controller.generateMouseEvent(x, y, 'b2c')
Exemplo n.º 22
0
def absoluteMotionWithTrajectory(source_x,
                                 source_y,
                                 dest_x,
                                 dest_y,
                                 mouseDelay=None,
                                 check=True):
    """
    Synthetize mouse absolute motion with trajectory. The 'trajectory' means that the whole motion
    is divided into several atomic movements which are synthetized separately.
    """
    if check:
        checkCoordinates(source_x, source_y)
        checkCoordinates(dest_x, dest_y)
    logger.log("Mouse absolute motion with trajectory to (%s,%s)" %
               (dest_x, dest_y))

    dx = float(dest_x - source_x)
    dy = float(dest_y - source_y)
    max_len = max(abs(dx), abs(dy))
    if max_len == 0:
        # actually, no motion requested
        return
    dx /= max_len
    dy /= max_len
    act_x = float(source_x)
    act_y = float(source_y)

    for _ in range(0, int(max_len)):
        act_x += dx
        act_y += dy
        if mouseDelay:
            doDelay(mouseDelay)
        registry.generateMouseEvent(int(act_x), int(act_y), name='abs')

    if mouseDelay:
        doDelay(mouseDelay)
    else:
        doDelay()
Exemplo n.º 23
0
 def double_click(self, button=1):
     self.widow_hide()
     x, y = self.get_center()
     registry.generateMouseEvent(x, y, 'b%sd' % button)
Exemplo n.º 24
0
 def move_cursor_to(self, x, y):
     """Moves the cursor to the x, y coordinates"""
     controller.generateMouseEvent(x, y, MOUSE_ABS)
Exemplo n.º 25
0
 def middle_click_to(self, x, y):
     """Middle clicks the cursor to the x, y coordinates"""
     if x >= 0 and y >= 0:
         controller.generateMouseEvent(x, y, "b2c")
Exemplo n.º 26
0
 def right_click_to(self, x, y):
     """Right clicks the cursor to the x, y coordinates"""
     if x >= 0 and y >= 0:
         controller.generateMouseEvent(x, y, "b3c")
Exemplo n.º 27
0
 def double_click(self, button = 1):
     self.widow_hide()
     x,y = self.get_center()
     registry.generateMouseEvent(x, y, 'b%sd' % button)
Exemplo n.º 28
0
 def point(self):
     x,y = self.get_center()
     registry.generateMouseEvent(x, y, 'abs')
Exemplo n.º 29
0
 def point(self):
     x, y = self.get_center()
     registry.generateMouseEvent(x, y, 'abs')
Exemplo n.º 30
0
def point(x, y, check=True):
    if check:
        checkCoordinates(x, y)
    logger.log("Pointing mouse cursor at (%s,%s)" % (x, y))
    registry.generateMouseEvent(x, y, 'abs')
    doDelay(config.actionDelay)