Looking at PyAutoGUI's source code the function
Looking at pyscreeze's source code the function
So it already has a looping mechanism built in, try giving a
locateCenterOnScreen
uses pyscreezehttps://github.com/asweigart/pyautogui/b...__.py#L205 Wrote:@raisePyAutoGUIImageNotFoundException def locateCenterOnScreen(*args, **kwargs): return pyscreeze.locateCenterOnScreen(*args, **kwargs) locateCenterOnScreen.__doc__ = pyscreeze.locateCenterOnScreen.__doc__
Looking at pyscreeze's source code the function
locateCenterOnScreen
has a parameter minSearchTime
- amount of time in seconds to repeat taking screenshots and trying to locate a match. The default of 0 performs a single search.https://github.com/asweigart/pyscreeze/b...__.py#L409 Wrote:def locateCenterOnScreen(image, **kwargs): """ TODO """ coords = locateOnScreen(image, **kwargs) if coords is None: return None else: return center(coords)
https://github.com/asweigart/pyscreeze/b...__.py#L363 Wrote:def locateOnScreen(image, minSearchTime=0, **kwargs): """TODO - rewrite this minSearchTime - amount of time in seconds to repeat taking screenshots and trying to locate a match. The default of 0 performs a single search. """ start = time.time() while True: try: screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here. retVal = locate(image, screenshotIm, **kwargs) try: screenshotIm.fp.close() except AttributeError: # Screenshots on Windows won't have an fp since they came from # ImageGrab, not a file. Screenshots on Linux will have fp set # to None since the file has been unlinked pass if retVal or time.time() - start > minSearchTime: return retVal except ImageNotFoundException: if time.time() - start > minSearchTime: if USE_IMAGE_NOT_FOUND_EXCEPTION: raise else: return None
So it already has a looping mechanism built in, try giving a
minSearchTime