I'm working on a project in python that's meant to be clicking in specific locations in another program window. Currently, I'm taking a screenshot and then detecting the button in said screenshot with OpenCV, and then clicking there. I feel that scanning the whole screenshot every frame for this button to be quite a bit of work. This button will show up in the same spot relative to the program window. This whole process is meant to account for the window not being in the same exact location. I wanted to know if there was a way to detect the position of a program window without taking a screenshot and having to sift through it? Like, program.getPosition or something, and getting an X Y position of maybe its upper-left pixel. From there I could add the numbers I need to navigate to the button. Does such a thing exist?
Asked
Active
Viewed 239 times
1
-
what program ? Is it your window create by your script ? – furas Aug 04 '19 at 08:27
-
module [pyautogui](https://pyautogui.readthedocs.io/en/latest/) works the same - it uses image to find object on screen. And then it can click it. – furas Aug 04 '19 at 08:29
-
@furas It's not a window created by my script. It's a separate program entirely. – CuriousBo Aug 04 '19 at 08:32
-
@furas Also, that's not quite what I'm going for. Currently, I am doing just that: scanning an image to find an object on the screen. What I was hoping for was some way to get the position of another window that's open. If I know where the upper left pixel of that window is, I can just add 500 to its Y and 300 to its X to get to the button. Is there such a shortcut? – CuriousBo Aug 04 '19 at 08:34
-
as I said pyautogui works the same it uses image of button with `locateOnScreen()` to find button on full screen. But knowing window's position you could skip it. On Linux you can use external program `xwininfo` if you know windows full title - `xwininfo -name "about - Firefox"`. – furas Aug 04 '19 at 08:42
-
using Google "python window position " I found in few seconds [Get window position & size with python](https://stackoverflow.com/questions/7142342/get-window-position-size-with-python). If there is solution for your system then I can only say: using Google you could get this long time ago. – furas Aug 04 '19 at 08:45
-
Which OS is this running on? How you'd go about getting a program's active windows will depend on the operating system (and system) that runs the program. – MatsLindh Aug 04 '19 at 09:25
-
@MatsLindh It's Windows. – CuriousBo Aug 05 '19 at 01:15
-
In that case the answer linked above will give you what you want. – MatsLindh Aug 05 '19 at 08:19