How to use the pyautogui.locateOnScreen function in PyAutoGUI

To help you get started, we’ve selected a few PyAutoGUI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse / sumo / tests / netedit / neteditTestFunctions.py View on Github external
def getReferenceMatch(neProcess, waitTime):
    """
    @brief obtain reference referencePosition (pink square)
    """
    # show information
    print("Finding reference")
    try:
        # capture screen and search reference
        positionOnScreen = pyautogui.locateOnScreen(_REFERENCE_PNG, waitTime)
    except Exception as e:
        # we cannot specify the exception here because some versions of pyautogui use one and some don't
        print(e)
        positionOnScreen = None
    # check if pos was found
    if positionOnScreen:
        # adjust position to center
        referencePosition = (positionOnScreen[0] + 16, positionOnScreen[1] + 16)
        # break loop
        print("TestFunctions: 'reference.png' found. Position: " +
              str(referencePosition[0]) + " - " + str(referencePosition[1]))
        # check that position is consistent (due scaling)
        if referencePosition != (304, 168):
            print("TestFunctions: Position of 'reference.png' isn't consistent. Check that interface scaling " +
                  "is 100% (See #3746)")
        return referencePosition
github asweigart / sushigoroundbot / sushigoroundbot.py View on Github external
def getGameRegion():
    """Obtains the region that the Sushi Go Round game is on the screen and assigns it to GAME_REGION. The game must be at the start screen (where the PLAY button is visible)."""
    global GAME_REGION

    # identify the top-left corner
    logging.info('Finding game region...')
    region = pyautogui.locateOnScreen(imPath('top_right_corner.png'))
    if region is None:
        raise Exception('Could not find game on screen. Is the game visible?')

    # calculate the region of the entire game
    topRightX = region[0] + region[2] # left + width
    topRightY = region[1] # top
    GAME_REGION = (topRightX - 640, topRightY, 640, 480) # the game screen is always 640 x 480
    logging.info('Game region found: %s' % (GAME_REGION,))
github IFinners / automate-the-boring-stuff-projects / Chapter 18 / im_bot.py View on Github external
online_select = pyautogui.locateOnScreen('online-friend.png')
    if online_select is None:
        print('Friend not found or currently offline.')
        return
    else:
        pyautogui.doubleClick(online_select)

    attempts = 3
    while attempts > 0:
        message_box = pyautogui.locateOnScreen('message.png')
        pyautogui.click(message_box)
        pyautogui.typewrite(message)

        # If it can no longer be found it is because the message was entered.
        if pyautogui.locateOnScreen('message.png') is None:
            pyautogui.press('enter')
            pyautogui.press('esc')
            print('Message sent to {}'.format(name))
            break
        else:
            if attempts == 1:
                print('Unable to send message to {}.'.format(name))
                pyautogui.press('esc')

            else:
                print('Sending message to {} failed. Another {} attempts will '
                      'be made before moving on.'.format(name, attempts))

            attempts -= 1
github niksaz / dota2-expert-demo / dotaenv / dota_runner.py View on Github external
def __wait_until_image_is_displayed(image_path):
    # Wait for 60 seconds at maximum
    for _ in range(60):
        try:
            point = gui.locateOnScreen(image_path)
            if point:
                return True
        except ImageNotFoundException:
            pass
        time.sleep(1.0)
    return False
github ayushxx7 / Facebook-Auto-Liker / autoLikeFB.py View on Github external
pyautogui.scroll(-m)
    cnt += 1
    if cnt == 2:
        m -= 4
        cnt = 0


#pyautogui.scroll(-760)

# 760 scroll difference b/w 1st and 4th image line distance
'''

pyautogui.hotkey('alt', 'tab')
for z in range(0,100):
    time.sleep(0.2)
    if (pyautogui.locateOnScreen('newlikeButton.png')) != None:
        pyautogui.press('l')
    pyautogui.press('right')
    time.sleep(0.2)

'''
<a tabindex="-1" role="button" href="#" data-testid="fb-ufi-likelink" class="UFILikeLink _4x9- _4x9_ _48-k" aria-pressed="false">Like</a>
github lukegarbutt / RunescapeBots / GeMercher.py View on Github external
def move_mouse_to_box(image_of_box, top_left_corner, bottom_right_corner):
	box_to_click = pyautogui.locateOnScreen(image_of_box, region=(top_left_corner[0], top_left_corner[
											1], bottom_right_corner[0] - top_left_corner[0], bottom_right_corner[1] - top_left_corner[1]))
	random_x = random.randint(0, box_to_click[2])
	random_y = random.randint(0, box_to_click[3])
	realmouse.move_mouse_to(box_to_click[0] + random_x, box_to_click[1] + random_y)