Exemple #1
0
def _general_click(where=None,
                   clicks=None,
                   duration=None,
                   in_region=None,
                   button=None):
    """General Mouse Click.

    :param where: Location , image name or Pattern.
    :param clicks: Number of mouse clicks.
    :param duration: Speed of hovering from current location to target.
    :param in_region: Region object in order to minimize the area.
    :param button: Mouse button clicked (can be left, right, middle, 1, 2, 3).
    :return: None.
    """

    if duration is None:
        duration = Settings.move_mouse_delay

    if isinstance(where, Pattern):
        _click_pattern(where, clicks, duration, in_region, button)

    elif isinstance(where, str):
        a_match = text_search_by(where, True, in_region)
        if a_match is not None:
            click_location = Location(a_match['x'] + a_match['width'] / 2,
                                      a_match['y'] + a_match['height'] / 2)
            _click_at(click_location, clicks, duration, button)

    elif isinstance(where, Location):
        _click_at(where, clicks, duration, button)

    else:
        raise ValueError(INVALID_GENERIC_INPUT)
Exemple #2
0
def _mouse_press_release(where=None, action=None, button=None, in_region=None):
    """Mouse press/release.

    :param where: Location , image name or Pattern.
    :param action: 'press' or 'release'.
    :param button: 'left','right' or 'middle'.
    :param in_region: Region object in order to minimize the area.
    :return: None.
    """
    if isinstance(where, Pattern):
        needle = cv2.imread(where.get_file_path())
        height, width, channels = needle.shape
        p_top = positive_image_search(pattern=where, region=in_region)
        if p_top is None:
            raise FindError('Unable to click on: %s' % where.get_file_path())
        possible_offset = where.get_target_offset()
        if possible_offset is not None:
            location = Location(p_top.x + possible_offset.x,
                                p_top.y + possible_offset.y)
            pyautogui.moveTo(location.x, location.y)
            if action == 'press':
                pyautogui.mouseDown(location.x, location.y, button)
            elif action == 'release':
                pyautogui.mouseUp(location.x, location.y, button)
        else:
            location = Location(p_top.x + width / 2, p_top.y + height / 2)
            pyautogui.moveTo(location.x, location.y)
            if action == 'press':
                pyautogui.mouseDown(location.x, location.y, button)
            elif action == 'release':
                pyautogui.mouseUp(location.x, location.y, button)
    elif isinstance(where, str):
        mouse = Controller()
        a_match = text_search_by(where, True, in_region)
        if a_match is not None:
            location = Location(a_match['x'] + a_match['width'] / 2,
                                a_match['y'] + a_match['height'] / 2)
            mouse.move(location.x, location.y)
            if action == 'press':
                mouse.press(button)
            elif mouse == 'release':
                mouse.release(button)