本文整理汇总了Python中pyautogui.position方法的典型用法代码示例。如果您正苦于以下问题:Python pyautogui.position方法的具体用法?Python pyautogui.position怎么用?Python pyautogui.position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyautogui
的用法示例。
在下文中一共展示了pyautogui.position方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_moveToWithTween
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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),
)
示例2: test_moveRelWithTween
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [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),
)
示例3: adjust_click_position
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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
示例4: fromPosition
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
def fromPosition():
raw_input("Hover over the location you want to click and press enter")
return position()
示例5: run
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
def run(self):
while self.running:
self.click()
sleep(self.time_step)
if (self.x, self.y) != position():
self.running=False
示例6: test_position
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [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)
示例7: test_moveTo
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [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)
示例8: repeat_click
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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)
示例9: mouse_pos
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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
示例10: position
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
def position():
print(pyautogui.position())
示例11: get_widget_location
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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
示例12: position_is_inside_bounds
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
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
示例13: perform_click
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [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
示例14: get_mouse_position
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
def get_mouse_position():
return pyautogui.position()
# Return screen size
示例15: test_simple
# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import position [as 别名]
def test_simple(self):
width, height = pyautogui.size()
toPoint = (width//2, height//2)
hc = HumanClicker()
hc.move(toPoint)
self.assertTrue(pyautogui.position() == toPoint)