当前位置: 首页>>代码示例>>Python>>正文


Python pyautogui.moveTo方法代码示例

本文整理汇总了Python中pyautogui.moveTo方法的典型用法代码示例。如果您正苦于以下问题:Python pyautogui.moveTo方法的具体用法?Python pyautogui.moveTo怎么用?Python pyautogui.moveTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyautogui的用法示例。


在下文中一共展示了pyautogui.moveTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_moveRelWithTween

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def test_moveRelWithTween(self):
        origin = self.center - P(100, 100)
        delta = P(200, 200)
        destination = origin + delta

        def resetMouse():
            pyautogui.moveTo(*origin)
            mousepos = P(*pyautogui.position())
            self.assertEqual(mousepos, origin)

        for tweenName in self.TWEENS:
            tweenFunc = getattr(pyautogui, tweenName)
            resetMouse()
            pyautogui.moveRel(delta.x, delta.y, duration=pyautogui.MINIMUM_DURATION * 2, tween=tweenFunc)
            mousepos = P(*pyautogui.position())
            self.assertEqual(
                mousepos,
                destination,
                "%s tween move failed. mousepos set to %s instead of %s" % (tweenName, mousepos, destination),
            ) 
开发者ID:asweigart,项目名称:pyautogui,代码行数:22,代码来源:test_pyautogui.py

示例2: basic_recovery

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def basic_recovery():
        """Method that contains steps for basic recovery attempt, which
        involves clearing any interaction-blocking browser popups.

        Returns:
            bool: True if recovery was successful; False otherwise.
        """
        Log.log_debug("Attempting Basic Recovery.")

        if cfg.config.general.is_direct_control:
            pyautogui.moveTo(1, 1)
            pyautogui.press('esc')
            sleep(0.5)
            pyautogui.press('space')
            sleep(0.5)
            pyautogui.press('f10')
            sleep(0.5)

        try:
            if kca_u.kca.find_kancolle():
                return True
        except FindFailed:
            pass

        return False 
开发者ID:mrmin123,项目名称:kcauto,代码行数:27,代码来源:recovery.py

示例3: _Input

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def _Input(mousex=0, mousey=0, click=0, keys=None, delay='0.2'):
    import pyautogui
    '''Control the user's mouse and/or keyboard.
       Arguments:
         mousex, mousey - x, y co-ordinates from top left of screen
         keys - list of keys to press or single key
    '''
    g = Globals()
    screenWidth, screenHeight = pyautogui.size()
    mousex = int(screenWidth / 2) if mousex == -1 else mousex
    mousey = int(screenHeight / 2) if mousey == -1 else mousey
    exit_cmd = [('alt', 'f4'), ('ctrl', 'shift', 'q'), ('command', 'q')][(g.platform & -g.platform).bit_length() - 1]

    if keys:
        if '{EX}' in keys:
            pyautogui.hotkey(*exit_cmd)
        else:
            pyautogui.press(keys, interval=delay)
    else:
        pyautogui.moveTo(mousex, mousey)
        if click:
            pyautogui.click(clicks=click)

    Log('Input command: Mouse(x={}, y={}, click={}), Keyboard({})'.format(mousex, mousey, click, keys)) 
开发者ID:Sandmann79,项目名称:xbmc,代码行数:26,代码来源:playback.py

示例4: setUp

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def setUp(self):
        self.oldFailsafeSetting = pyautogui.FAILSAFE
        pyautogui.FAILSAFE = False
        pyautogui.moveTo(42, 42)  # make sure failsafe isn't triggered during this test
        pyautogui.FAILSAFE = True 
开发者ID:asweigart,项目名称:pyautogui,代码行数:7,代码来源:test_pyautogui.py

示例5: test_position

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def test_position(self):
        mousex, mousey = pyautogui.position()

        self.assertTrue(isinstance(mousex, int), "Type of mousex is %s" % (type(mousex)))
        self.assertTrue(isinstance(mousey, int), "Type of mousey is %s" % (type(mousey)))

        # Test passing x and y arguments to position().
        pyautogui.moveTo(mousex + 1, mousey + 1)
        x, y = pyautogui.position(mousex, None)
        self.assertEqual(x, mousex)
        self.assertNotEqual(y, mousey)

        x, y = pyautogui.position(None, mousey)
        self.assertNotEqual(x, mousex)
        self.assertEqual(y, mousey) 
开发者ID:asweigart,项目名称:pyautogui,代码行数:17,代码来源:test_pyautogui.py

示例6: test_pause

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def test_pause(self):
        oldValue = pyautogui.PAUSE

        startTime = time.time()
        pyautogui.PAUSE = 0.35  # there should be a 0.35 second pause after each call
        pyautogui.moveTo(1, 1)
        pyautogui.moveRel(0, 1)
        pyautogui.moveTo(1, 1)

        elapsed = time.time() - startTime
        self.assertTrue(1.0 < elapsed < 1.1, "Took %s seconds, expected 1.0 < 1.1 seconds." % (elapsed))

        pyautogui.PAUSE = oldValue  # restore the old PAUSE value 
开发者ID:asweigart,项目名称:pyautogui,代码行数:15,代码来源:test_pyautogui.py

示例7: test_moveTo

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def test_moveTo(self):
        # moving the mouse
        desired = self.center
        pyautogui.moveTo(*desired)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # no coordinate specified (should be a NO-OP)
        pyautogui.moveTo(None, None)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # moving the mouse to a new location
        desired += P(42, 42)
        pyautogui.moveTo(*desired)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # moving the mouse over time (1/5 second)
        desired -= P(42, 42)
        pyautogui.moveTo(desired.x, desired.y, duration=0.2)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # Passing a list instead of separate x and y.
        desired += P(42, 42)
        pyautogui.moveTo(list(desired))
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # Passing a tuple instead of separate x and y.
        desired += P(42, 42)
        pyautogui.moveTo(tuple(desired))
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # Passing a sequence-like object instead of separate x and y.
        desired -= P(42, 42)
        pyautogui.moveTo(desired)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired) 
开发者ID:asweigart,项目名称:pyautogui,代码行数:43,代码来源:test_pyautogui.py

示例8: test_failsafe

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def test_failsafe(self):
        self.oldFailsafeSetting = pyautogui.FAILSAFE

        pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with
        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = True
            # When move(), moveTo(), drag(), or dragTo() moves the mouse to a
            # failsafe point, it shouldn't raise the fail safe. (This would
            # be annoying. Only a human moving the mouse to a failsafe point
            # should trigger the failsafe.)
            pyautogui.moveTo(x, y)

            pyautogui.FAILSAFE = False
            pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with (for the next iteration)

        pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with
        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = True
            pyautogui.moveTo(x, y)  # This line should not cause the fail safe exception to be raised.

            # A second pyautogui function call to do something while the cursor is in a fail safe point SHOULD raise the failsafe:
            self.assertRaises(pyautogui.FailSafeException, pyautogui.press, "esc")

            pyautogui.FAILSAFE = False
            pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with (for the next iteration)

        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = False
            pyautogui.moveTo(x, y)  # This line should not cause the fail safe exception to be raised.

            # This line shouldn't cause a failsafe to trigger because FAILSAFE is set to False.
            pyautogui.press("esc")

        pyautogui.FAILSAFE = self.oldFailsafeSetting 
开发者ID:asweigart,项目名称:pyautogui,代码行数:36,代码来源:test_pyautogui.py

示例9: click_image

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def click_image(image, pos, action, timestamp, offset=5):
    img = cv2.imread(image)
    height, width, channels = img.shape
    pyautogui.moveTo(pos[0] + r(width / 2, offset), pos[1] + r(height / 2, offset),
                     timestamp)
    pyautogui.click(button=action) 
开发者ID:drov0,项目名称:python-imagesearch,代码行数:8,代码来源:imagesearch.py

示例10: is_on_screen

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def is_on_screen(this, accuracy=0.14):
        this = this + '.png'
        Screenshot.shot()
        small_image = cv2.imread(this)
        h, w, c = small_image.shape
        large_image = cv2.imread('playing.png')
        result = cv2.matchTemplate(
            small_image, large_image, cv2.TM_SQDIFF_NORMED)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
        #print('ImageCoordinate::is_on_screen => ' + this + ' ' + str(min_val))
        mn, _, mn_loc, mx_loc = cv2.minMaxLoc(result)
        mp_x, mp_y = mn_loc
        m_x, m_y = mx_loc
        # print(mn_loc)
        # top_left = mn_loc
        # mx_right = mx_loc
        bt_rt = (mn_loc[0], mn_loc[1])
        bt_rtw = (mn_loc[0]+w, mn_loc[1]+h)
        # cv2.rectangle(large_image,top_left,bt_rt,255,2)

        # bt_rt =(mx_right[0]+h,mx_right[1]+w)
        # cv2.rectangle(large_image,mx_right,bt_rt,255,2)
        # cv2.imwrite('result_'+this.replace('images/',''), large_image)
        # print('saved')
        #pyautogui.moveTo(mp_x, mp_y)
        print(min_val)
        if min_val > accuracy:
            return False
        else:
            mn, _, mn_loc, _ = cv2.minMaxLoc(result)
            mp_x, mp_y = mn_loc
            ordinal = random.randrange(1, 15)
            a = random.randrange(-ordinal, ordinal)
            b = random.randrange(-ordinal, ordinal)
            location = [mp_x + w / 2+a, mp_y + h / 2+b, bt_rt, bt_rtw, min_val]
            return location 
开发者ID:Sunuba,项目名称:roc,代码行数:38,代码来源:ImageCoordinate.py

示例11: coords

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def coords(this, shot=True):
        this = this + '.png'
        if shot:
            Screenshot.shot()
        else:
            print('No screenshot')
        small_image = cv2.imread(this)
        h, w, c = small_image.shape
        large_image = cv2.imread('playing.png')
        result = cv2.matchTemplate(
            small_image, large_image, cv2.TM_SQDIFF_NORMED)
        min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
        # print('ImageCoordinate::coords => ' + this + ' ' + str(min_val))
        mn, _, mn_loc, mx_loc = cv2.minMaxLoc(result)
        mp_x, mp_y = mn_loc
        # #pyautogui.moveTo(mp_x, mp_y)
        # top_left = mn_loc
        # mx_right = mx_loc
        # bt_rt =(top_left[0]+h,top_left[1]+w)
        # cv2.rectangle(large_image,top_left,bt_rt,255,2)

        # bt_rt =(mx_right[0]+h,mx_right[1]+w)
        # cv2.rectangle(large_image,mx_right,bt_rt,255,2)
        # cv2.imwrite('result_'+this.replace('images/',''), large_image)
        # print('saved'+str(min_val))
        if min_val > 0.2:
            return [0, 0, min_val]
        mn, _, mn_loc, _ = cv2.minMaxLoc(result)
        mp_x, mp_y = mn_loc
        ordinal = random.randrange(1, 15)
        a = random.randrange(-ordinal, ordinal)
        b = random.randrange(-ordinal, ordinal)

        location = [mp_x + w / 2+a, mp_y + h / 2+b, min_val]
        return location 
开发者ID:Sunuba,项目名称:roc,代码行数:37,代码来源:ImageCoordinate.py

示例12: move_to

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def move_to(self, *coordinates):
        '''Moves the mouse pointer to an absolute coordinates.

        ``coordinates`` can either be a Python sequence type with two values
        (eg. ``(x, y)``) or separate values ``x`` and ``y``:

        | Move To         | 25             | 150       |     |
        | @{coordinates}= | Create List    | 25        | 150 |
        | Move To         | ${coordinates} |           |     |
        | ${coords}=      | Evaluate       | (25, 150) |     |
        | Move To         | ${coords}      |           |     |


        X grows from left to right and Y grows from top to bottom, which means
        that top left corner of the screen is (0, 0)
        '''
        if len(coordinates) > 2 or (len(coordinates) == 1 and
                                    type(coordinates[0]) not in (list, tuple)):
            raise MouseException('Invalid number of coordinates. Please give '
                                 'either (x, y) or x, y.')
        if len(coordinates) == 2:
            coordinates = (coordinates[0], coordinates[1])
        else:
            coordinates = coordinates[0]
        try:
            coordinates = [int(coord) for coord in coordinates]
        except ValueError:
            raise MouseException('Coordinates %s are not integers' %
                                 (coordinates,))
        ag.moveTo(*coordinates) 
开发者ID:eficode,项目名称:robotframework-imagehorizonlibrary,代码行数:32,代码来源:_mouse.py

示例13: perform_click

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def perform_click(x, y, double=False):
	old_position = pyautogui.position()
	if double:
		pyautogui.doubleClick(x=x, y=y, interval=0.1)
	else:
		pyautogui.click(x=x, y=y)
	pyautogui.moveTo(old_position)

# Press key 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:11,代码来源:tools.py

示例14: move_mouse_to

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def move_mouse_to(position):
	pyautogui.moveTo(position) 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:4,代码来源:tools.py

示例15: Click

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import moveTo [as 别名]
def Click(targetPosition):
    """
    点击屏幕上的某个点
    :param targetPosition:
    :return:
    """
    if targetPosition is None:
        print('未检测到目标')
    else:

        pyautogui.moveTo(targetPosition, duration=0.20)
        pyautogui.click()
        time.sleep(random.randint(500, 1000) / 1000)

        # time.sleep(random.randint(100, 150) / 1000) 
开发者ID:li-zheng-hao,项目名称:yysScript,代码行数:17,代码来源:YuHunModule.py


注:本文中的pyautogui.moveTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。