Locate something on the screen using PyScreeze on Python

  • locateOnScreen(image, grayscale=False) – Returns (left, top, width, height) coordinate of first found instance of the image on the screen. Returns None if not found on the screen.
  • locateCenterOnScreen(image, grayscale=False) – Returns (x, y) coordinates of the center of the first found instance of the image on the screen. Returns None if not found on the screen.
  • locateAllOnScreen(image, grayscale=False) – Returns a generator that yields (left, top, width, height) tuples for where the image is found on the screen.
  • locate(needleImage, haystackImage, grayscale=False) – Returns (left, top, width, height) coordinate of first found instance of needleImage in haystackImage. Returns None if not found on the screen.
  • locateAll(needleImage, haystackImage, grayscale=False) – Returns a generator that yields (left, top, width, height) tuples for where needleImage is found in haystackImage.

 

import pyscreeze
button7location = pyscreeze.locateOnScreen('calc7key.png')
button7location
(1416, 562, 50, 41)
button7x, button7y = pyscreeze.center(button7location)
button7x, button7y
(1441, 582)
pyscreeze.click(button7x, button7y)  # clicks the center of where the 7 button was found
import pyscreeze
x, y = pyscreeze.locateCenterOnScreen('calc7key.png')
pyscreeze.click(x, y)
import pyscreeze
for pos in pyscreeze.locateAllOnScreen('someButton.png')
...   print(pos)
...
(1101, 252, 50, 50)
(59, 481, 50, 50)
(1395, 640, 50, 50)
(1838, 676, 50, 50)
list(pyscreeze.locateAllOnScreen('someButton.png'))
[(1101, 252, 50, 50), (59, 481, 50, 50), (1395, 640, 50, 50), (1838, 676, 50, 50)]
import pyscreeze
button7location = pyscreeze.locateOnScreen('calc7key.png', grayscale=True)
button7location
(1416, 562, 50, 41)

References
https://pypi.org/project/PyScreeze/