Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug with pywin32 window size detector #1777

Closed
Martyn0324 opened this issue Oct 16, 2021 · 1 comment
Closed

Possible bug with pywin32 window size detector #1777

Martyn0324 opened this issue Oct 16, 2021 · 1 comment

Comments

@Martyn0324
Copy link

I had some problems trying to capture the window of a game to do some Reinforcement Learning. The package I'm using uses win32gui to get the window and the size of that window. However, it wasn't getting the window size correctly, returning a cropped screenshot every time a frame was captured.
I had the same problem when testing this function with PyGetWindow and, though I couldn't find a solution for Pywin32, I found a solution for PyGetWindow and it applies for Pywin32 too. The solution is simply importing PyAutoGUI. I don't know why that happens, though, and since I couldn't find the solution for pywin32 through googling, I decided to post this here.

PS: I'm using an outdated version of pywin32. I don't know if I discovered a bug, if it's a known bug or if I just did something wrong.

Expected behavior and actual behavior.

Expected: Detect an application window size, which is about width=1015 and height=678 (obtained through sprite extraction) - offsets ignored.

Actual behavior: The application window has been correctly detected. However, the size detected was incorrect, which was width=816, height=544, x_offset=2 and y_offset=26, resulting in loss of necessary data.

Steps to reproduce the problem.

  • execute the desired application in window mode.
  • import win32gui;
  • assign win32gui.FindWindow(None, [application_window_name]) to a variable
  • call print(win32gui.GetClientRect(variable))
  • compare the output with the real width and height of such window (this can be done by taking a screenshot and selecting the window in Paint or thorugh a Sprite Detector - in my case, I used spritex==0.1.3)

Version of Python and pywin32: Python == 3.8.8 (Conda) || pywin32 == 227

This problem seems to be solved when pyautogui is imported into the code
I've tried importing pyautogui since this method worked when dealing with PyGetWindow

import win32gui

window = win32gui.FindWindow(None, 'Jigoku Kisetsukan: Sense of the seasons v.1.09')

print(win32gui.GetClientRect(window))
@mhammond
Copy link
Owner

pywin32 just wraps the win32 functions - it doesn't do any processing of the data returned from GetClientRect etc, so I suspect there's something else going on, possibly to do with DPI etc. You might like to follow the instructions at https://github.com/mhammond/pywin32#support, but I don't see any evidence of a pywin32 bug here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants