def _unpackXY(x, y): """If x is a sequence and y is None, returns x[0], y[0]. Else, returns x, y. On functions that receive a pair of x,y coordinates, they can be passed as separate arguments, or as a single two-element sequence. """ if isinstance(x, str): # x parameter is the string of an image filename to find and click on: x, y = center(locateOnScreen(x)) elif isinstance(x, collectionsSequence): if len(x) == 2: # x is a two-integer tuple: (x, y) if y is None: x, y = x else: raise ValueError( 'When passing a sequence as the x argument, the y argument must not be passed (received {0}).' .format(repr(y))) elif len(x) == 4: # x is a four-integer tuple: (left, top, width, height) if y is None: x, y = center(x) else: raise ValueError( 'When passing a sequence as the x argument, the y argument must not be passed (received {0}).' .format(repr(y))) else: raise ValueError( 'The supplied sequence must have exactly 2 or exactly 4 elements ({0} were received).' .format(len(x))) else: pass # x and y are just number values return x, y
def locate(self, image, type='', **kwargs): if type == "base64": needle_image = BytesIO(base64.b64decode(image)) else: needle_image = Image.open(image) haystack_image = self.get_screenshot() if res := pyscreeze.locate(needle_image, haystack_image) != None: position = [] self.x = pyscreeze.center(res)[0] self.y = pyscreeze.center(res)[1] position.append(pyscreeze.center(res)[0]) position.append(pyscreeze.center(res)[1]) return True
def click_png(self, png): if self.found_image(png): location = pyscreeze.locateOnScreen(png) if location: self.log('Found image %s' % png) center_x, center_y = pyscreeze.center(location) self.click_position(center_x, center_y) else: self.log('Could not find the image: %s' % png) raise Exception('Locate image %s failed.' % png)
def click_png(png): # location = pyautogui.locateOnScreen(png) location = pyscreeze.locateOnScreen(png) if location: print(location) log('Found image%s' % png) # center_x, center_y = pyautogui.locateCenterOnScreen(png) center_x, center_y = pyscreeze.center(location) click_position(center_x, center_y) else: # log('Could not find the image: %s' % png) raise Exception('Locate image %s failed.' % png)
def _unpackXY(x, y): """If x is a sequence and y is None, returns x[0], y[0]. Else, returns x, y. On functions that receive a pair of x,y coordinates, they can be passed as separate arguments, or as a single two-element sequence. """ if isinstance(x, str): # x parameter is the string of an image filename to find and click on: x, y = center(locateOnScreen(x)) elif isinstance(x, collectionsSequence): if len(x) == 2: if y is None: x, y = x else: raise ValueError('When passing a sequence at the x argument, the y argument must not be passed (received {0}).'.format(repr(y))) else: raise ValueError('The supplied sequence must have exactly 2 elements ({0} were received).'.format(len(x))) else: pass # x and y are just number values return x, y
def test_center(self): self.assertEqual((10, 10), pyscreeze.center((0, 0, 20, 20))) self.assertEqual((10, 10), pyscreeze.center((5, 5, 10, 10))) self.assertEqual((100, 100), pyscreeze.center((0, 0, 200, 200))) self.assertEqual((100, 100), pyscreeze.center((50, 50, 100, 100)))
print(" E ") print(" R ") input0 = input("Would you Like to hack (C)ookie Clicker or (D)oge Clicker") if input0 == "C": input1 = input( "Would you Like to (I)nfinity Tap or Tap the cookie a (S)pecified amount of times" ) if input1 == "I": screen = pyscreeze.screenshot() cookie = pyscreeze.locateOnScreen('cookie.png') cookiex, cookiey = pyscreeze.center(cookie) pyautogui.moveTo(cookiex, cookiey) i = 0 while True: pyautogui.click() time.sleep(0.0005) i += 1 print(i) elif input1 == "S": input3 = int(input("Enter number of times cookie will be clicked")) screen = pyscreeze.screenshot() cookie = pyscreeze.locateOnScreen('cookie.png') cookiex, cookiey = pyscreeze.center(cookie)