本文整理汇总了Python中pyautogui.position函数的典型用法代码示例。如果您正苦于以下问题:Python position函数的具体用法?Python position怎么用?Python position使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了position函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_moveRel
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, None)
mousepos = P(*pyautogui.position())
self.assertEqual(mousepos, desired)
# move down
desired += P(0, 42)
pyautogui.moveRel(None, 42)
mousepos = P(*pyautogui.position())
self.assertEqual(mousepos, desired)
# move left
desired += P(-42, 0)
pyautogui.moveRel(-42, None)
mousepos = P(*pyautogui.position())
self.assertEqual(mousepos, desired)
# move up
desired += P(0, -42)
pyautogui.moveRel(None, -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)
示例2: main
def main():
while True:
position = pyautogui.position()
time.sleep(60)
if position == pyautogui.position():
pyautogui.moveRel(0,-1)
pyautogui.moveRel(0,1)
示例3: Start
def Start(pos):
pyautogui.FAILSAFE = False
global root, running
im=pyautogui.screenshot()
pos['text']=str(pyautogui.position())
rgb['text']=str(im.getpixel(pyautogui.position()))
root.update_idletasks()
root.after(10, lambda:Start(pos))
示例4: func
def func():
self.screenshot_button.config(state='disabled')
for second in reversed(range(4)):
self.screenshot_label.config(
text='Deselect the game window %s' % second)
if second != 0:
time.sleep(1)
region = []
for second in reversed(range(4)):
self.screenshot_label.config(
text='Place the mouse at the top left\nof the game\'s title bar %s' % second)
if second != 0:
time.sleep(1)
constant_top_left = pyautogui.position()
region.extend(constant_top_left)
for second in reversed(range(4)):
self.screenshot_label.config(
text='Place the mouse at the bottom right\nof the game\'s title bar %s' % second)
if second != 0:
time.sleep(1)
constant_bottom_right = pyautogui.position()
region.extend(
(constant_bottom_right[0] - constant_top_left[0],
constant_bottom_right[1] - constant_top_left[1])
)
self.deselected_screenshot = pyautogui.screenshot(region=region)
pyautogui.click()
self.selected_screenshot = pyautogui.screenshot(region=region)
for second in reversed(range(4)):
self.screenshot_label.config(
text='Place mouse at the top left\nof the entire game window %s' % second)
if second != 0:
time.sleep(1)
top_left = pyautogui.position()
for second in reversed(range(4)):
self.screenshot_label.config(
text='Place mouse at the bottom right\nof the entire game window %s' % second)
if second != 0:
time.sleep(1)
bottom_right = pyautogui.position()
self.screen_size = [
constant_top_left[0] - top_left[0],
constant_top_left[1] - top_left[1],
bottom_right[0] - constant_bottom_right[0],
bottom_right[1] - constant_bottom_right[1]
]
self.screenshot_taken = True
self.screenshot_label.config(text='Screenshot Taken')
self.screenshot_button.config(
state='normal', text='Retake Screenshot')
示例5: v_scroll_on_android
def v_scroll_on_android(scroll_value=20, locate_first_on_center = True, scrollDown = True):
# Locate the mouse on screen center
if(locate_first_on_center is True):
locate_on_center()
# Simulate drag and drop
# pyautogui.mouseDown();
x, y = pyautogui.position()[0], pyautogui.position()[1]
if(scrollDown is True):
y = y - scroll_value;
else:
y = y + scroll_value;
pyautogui.dragTo(x, y)
示例6: showLocation
def showLocation():
lastLoc = (0,0)
newLoc = (1,0)
while lastLoc != newLoc:
x, y = pyautogui.position()
time.sleep(0.25)
locX.delete(0,END)
locY.delete(0,END)
locX.insert(0,x)
locY.insert(0,y)
lastLoc = newLoc
newLoc = pyautogui.position()
示例7: onClick
def onClick(self, mouse_button):
if mouse_button == 4: #scroll up
prev = pyautogui.position()
pyautogui.moveTo(0, pyautogui.size()[1], pause=False)
pyautogui.scroll(1)
pyautogui.moveTo(*prev, pause=False)
elif mouse_button == 5: #scroll dn
prev = pyautogui.position()
pyautogui.moveTo(0, pyautogui.size()[1], pause=False)
pyautogui.scroll(-1)
pyautogui.moveTo(*prev, pause=False)
else: #do nothing
pass
示例8: test_position
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)
示例9: auto_mouse
def auto_mouse():
auto.moveTo(450,450)
pos = auto.position()
auto.moveRel(-200,-200)
pos2 = auto.position()
for i in range(100 ):
try:
auto.moveTo(pos, duration = 1, tween = auto.easeInCubic)
auto.click()
auto.moveTo(pos, duration = 1)
auto.click()
auto.moveTo(pos2,duration = 1, tween = auto.easeInQuad)
except:
sys.exit()
示例10: test_moveTo
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)
# moving the mouse with only x specified
desired -= P(42, 0)
pyautogui.moveTo(desired.x, None)
mousepos = P(*pyautogui.position())
self.assertEqual(mousepos, desired)
# ...and only y specified
desired -= P(0, 42)
pyautogui.moveTo(None, desired.y)
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)
示例11: clickAndReturnMouseCoords
def clickAndReturnMouseCoords(coords):
orig_x,orig_y = pyautogui.position()
pyautogui.moveTo(coords[0],coords[1])
pyautogui.click()
logging.info('CLICK')
pyautogui.moveTo(orig_x, orig_y)
return
示例12: initialize
def initialize():
if not os.getenv('GOOGLE_API_KEY'):
print('*' * 80)
print('You must set GOOGLE_API_KEY to OS environments.')
print('Please check https://developers.google.com/maps/documentation/javascript/get-api-key')
print("export GOOGLE_API_KEY='blahblah' to ~/.bash_profile")
print('*' * 80)
raise NameError('GOOGLE_API_KEY')
print("Cursor on GPS button of xcode.")
input("press enter to continue")
gps_button_pos = pyautogui.position()
print("Cursor on GPX file of xcode. (pikapika.gpx)")
input("press enter to continue")
gpx_file_pos = pyautogui.position()
return gps_button_pos, gpx_file_pos
示例13: clickAndReturnMouse_point
def clickAndReturnMouse_point(point):
orig_x,orig_y = pyautogui.position()
pyautogui.moveTo(point['center'][0],point['center'][1])
pyautogui.click()
logging.info('CLICK')
pyautogui.moveTo(orig_x, orig_y)
return
示例14: __init__
def __init__(self,mag=100, browser='Firefox'):
top_bar = {'Firefox':100,'Chrome':115}
self.__x, self.__y = position()
self.__top_bar = top_bar[browser]
self.__y -= top_bar[browser]
self.__center = False
self.__mag = mag
示例15: test
def test():
i = 0
while i < 5:
i = i + 1
print pyautogui.position()
#window = pyautogui.locateCenterOnScreen('wood.png')
windows = pyautogui.locateAllOnScreen('key.png')
#if window is None:
# sys.exit('Could not find game on screen. Is the game visible?')
for window in windows:
l = window[0]
t = window[1]
w = window[2]
h = window[3]
time.sleep(0.1)
pyautogui.moveTo(l+w/2, t+h/2)