Python pyautogui.position() Examples

The following are 20 code examples of pyautogui.position(). 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_moveToWithTween(self):
        origin = self.center - P(100, 100)
        destination = self.center + P(100, 100)

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

        for tweenName in self.TWEENS:
            tweenFunc = getattr(pyautogui, tweenName)
            resetMouse()
            pyautogui.moveTo(destination.x, destination.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 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 #3
Source File: tools.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def adjust_click_position(click_x, click_y, window_width, window_height, dest_x, dest_y, dest_width, dest_height):
	# get screen size
	screen_width, screen_height = pyautogui.size()
	if screen_width > window_width and screen_height > window_height:
		# fit position to destination size
		new_x, new_y = fit_position_to_destination(click_x, click_y, window_width, window_height, dest_width, dest_height)
		#print('new_x: %d, new_y: %d, dest_x: %d, dest_y: %d' % (new_x, new_y, dest_x, dest_y))
		# scale to screen
		x = new_x + dest_x
		y = new_y + dest_y
	else:
		x = click_x
		y = click_y
	return (x, y)

# Perform a simple click or double click on x, y position 
Example #4
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_widget_location(widget):
	if widget:
		# get widget allocation (relative to parent)
		allocation = widget.get_allocation()
		# get widget position (relative to root window)
		if type(widget) in (Gtk.DrawingArea, Gtk.EventBox, Gtk.Socket):
			pos = widget.get_window().get_origin()
			return (pos.x, pos.y, allocation.width, allocation.height)
		else:
			pos_x, pos_y = widget.get_window().get_root_coords(allocation.x, allocation.y)
			return (pos_x, pos_y, allocation.width, allocation.height)
	else:
		return None

# Check if position is inside given bounds 
Example #5
Source File: control.py    From atbswp with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        """Initialize a new record."""
        self._header = HEADER

        self._capture = [self._header]
        self._lastx, self._lasty = pyautogui.position()
        self.mouse_sensibility = 21
        if getattr(sys, 'frozen', False):
            self.path = sys._MEIPASS
        else:
            self.path = Path(__file__).parent.absolute() 
Example #6
Source File: humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def move(self, toPoint, duration=2, humanCurve=None):
        fromPoint = pyautogui.position()
        if not humanCurve:
            humanCurve = HumanCurve(fromPoint, toPoint)

        pyautogui.PAUSE = duration / len(humanCurve.points)
        for point in humanCurve.points:
            pyautogui.moveTo(point) 
Example #7
Source File: test_humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def test_randomMove(self):
        width, height = pyautogui.size()
        toPoint = random.randint(width//2,width-1), random.randint(height//2,height-1)
        hc = HumanClicker()
        hc.move(toPoint)
        self.assertTrue(pyautogui.position() == toPoint) 
Example #8
Source File: test_humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def test_identityMove(self):
        toPoint = pyautogui.position()
        hc = HumanClicker()
        hc.move(toPoint)
        self.assertTrue(pyautogui.position() == toPoint) 
Example #9
Source File: test_humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def test_simple(self):
        width, height = pyautogui.size()
        toPoint = (width//2, height//2)
        hc = HumanClicker()
        hc.move(toPoint)
        self.assertTrue(pyautogui.position() == toPoint) 
Example #10
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def get_mouse_position():
	return pyautogui.position()

# Return screen size 
Example #11
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
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 
Example #12
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def position_is_inside_bounds(pos_x, pos_y, bounds_x, bounds_y, bounds_width, bounds_height):
	if pos_x > bounds_x and pos_x < (bounds_x + bounds_width) and pos_y > bounds_y and pos_y < (bounds_y + bounds_height):
		return True
	else:
		return False

# Fit position coordinates to given destination 
Example #13
Source File: AutoClick.py    From PyKinectTk with GNU General Public License v3.0 5 votes vote down vote up
def fromPosition():
        raw_input("Hover over the location you want to click and press enter")
        return position() 
Example #14
Source File: Commands.py    From roc with MIT License 5 votes vote down vote up
def position():
        print(pyautogui.position()) 
Example #15
Source File: Clicker.py    From roc with MIT License 5 votes vote down vote up
def mouse_pos(cls):
        rect =cls.find_window_movetop()
        posx = rect[0]
        poxy = rect[1]
        x, y = pyautogui.position()
        m_p = [x, y]
        return m_p 
Example #16
Source File: Clicker.py    From roc with MIT License 5 votes vote down vote up
def repeat_click(cls,say, adjust_x=0, adjust_y=0, interval=0.10):
        rect =cls.find_window_movetop()
        posx = rect[0]
        posy = rect[1]

        x, y = pyautogui.position()
        x = x+adjust_x
        y = y+adjust_y
        print(x, y)
        pyautogui.click(m.ceil(x+posx), m.ceil(y+posy), clicks=say-1, interval=interval) 
Example #17
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #18
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #19
Source File: AutoClick.py    From PyKinectTk with GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        while self.running:
            self.click()
            sleep(self.time_step)
            if (self.x, self.y) != position():
                self.running=False 
Example #20
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)