Python pyautogui.moveRel() Examples

The following are 4 code examples of pyautogui.moveRel(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyautogui , or try the search function .
Example #1
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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),
            ) 
Example #2
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #3
Source File: look_busy.py    From automate-the-boring-stuff-projects with MIT License 5 votes vote down vote up
def make_busy():
    """Moves mouse every 10 seconds to keep apps active
    Args:
        None
    Returns:
        None
    """
    print('Press CTRL-C to quit.')
    try:
        while True:
            pyautogui.moveRel(5, 0, 0.5)
            pyautogui.moveRel(-5, 0, 0.5)
            time.sleep(10)
    except KeyboardInterrupt:
        print('Process has quit...') 
Example #4
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def test_moveRel(self):
        # start at the center
        desired = self.center
        pyautogui.moveTo(*desired)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move down and right
        desired += P(42, 42)
        pyautogui.moveRel(42, 42)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move up and left
        desired -= P(42, 42)
        pyautogui.moveRel(-42, -42)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move right
        desired += P(42, 0)
        pyautogui.moveRel(42, 0)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move down
        desired += P(0, 42)
        pyautogui.moveRel(0, 42)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move left
        desired += P(-42, 0)
        pyautogui.moveRel(-42, 0)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

        # move up
        desired += P(0, -42)
        pyautogui.moveRel(0, -42)
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)

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

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

        # Passing a sequence-like object instead of separate x and y.
        desired += P(42, 42)
        pyautogui.moveRel(P(42, 42))
        mousepos = P(*pyautogui.position())
        self.assertEqual(mousepos, desired)