1

Within other applications on a Windows desktop I am wanting to get the x/y coordinates of certain things within the application. I have seen several freeware utilities that say they do this and have come across several scripts that say they do this as well. The application, I am trying to do this on has no API so I am wanting to automated the same office UI tasks every day to save me alot of time.

Someone with knowledge in this domain let me know what is the best way or the best way they know. Thank you

Red
  • 161
  • 1
  • 14
  • You can take a screenshot and do some image processing? That's usually simpler. Like this answer: https://stackoverflow.com/a/48669645/1016004 – Robin De Schepper May 23 '22 at 14:57
  • I am wanting the x/y to be able to tell the program the coordinates of where the button to click is ```pyautogui.click(x=690, y=487, clicks=1)``` however, for example the x/y coordinates is what I am wanting to know the best/easiest way to determine. – Red May 23 '22 at 16:41
  • 1
    The easiest way to determine that is likely going to be what I propose: take a screenshot and find your button in the image. You can use a package like `opencv` to help you with that. – Robin De Schepper May 24 '22 at 14:36

2 Answers2

1

you can see this api, it can solve your questions, not only desktop application, but also web applicatin, besides position, it can also return size of the control. https://www.clicknium.com/documents/api/python/uielement/get_property

justin
  • 197
  • 6
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32209082) – sm3sher Jul 14 '22 at 10:44
  • tried to check out the link, but when clicked it says it is not valid – Red Jul 26 '22 at 04:59
  • seems they update to their official site, I just update the link – justin Jul 26 '22 at 08:51
0

calling this function works:

def get_the_pos_of_the_mouse_Cursor():
    try:
        while True:
            x, y = pyautogui.position()
            positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
            print(positionStr, end='')
            print('\b' * len(positionStr), end='', flush=True)
    except KeyboardInterrupt:
    print('\n')
Red
  • 161
  • 1
  • 14