-
Notifications
You must be signed in to change notification settings - Fork 20
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
getActiveWindow() retrieving a window that isn't retrieved by getAllWindows (specifically, with windows search bar) #88
Comments
Hi!
|
Hi again!
As per the documentation, Besides, there is no way that I made a very simple snippet to try to reproduce your case:
The output was: Right after pressing "Run" in PyCharm:
After pressing Windows key:
Clicking in the desktop background (no user active window). Notice that some windows (especially system windows) will return an empty title:
Rapidly clicking between Start icon and the Search box in the taskbar:
FOUND!!! As you can see, the handle returned by GetForegroundWindow is 0 (I guess it's the python translation of the NULL value that pywin32 wrapper is making). Most likely it is the case described in the docs: "The foreground window can be NULL in certain circumstances, such as when a window is losing activation." In short, None is a valid return that must be handled accordingly. |
Got it. Thanks. |
By the way I resorted to refrain from PyWinCtl, and using win32gui from pywin32 instead as wrapper used by PyWinCtl is way too inefficient when used on windows. |
Well, PyWinCtl is actually using win32gui and win32api... can you please explain why PyWinCtl is inefficient? This will help me a lot to improve the module. Thx. |
Sure. the main issue comes with the wrapper for win32gui doesn't ever store any information (about the window itself, other than the core ones) after an instance of it is created. Instead it tries to call win32gui each time an attribute is used by the user. I do understand that it might be an intentional design decision for skae of not having to keep active sync for the window information, but it becomes quite laggy. I sometimes have to wait 5+ seconds before each call for my function that iterates over the entire list of foreground/background windows (where as my implmentation using win32gui directly result in almost instantanious output, as everything can be done without having to iterate over all windows (for search/access) multiple times.) A quick fix that I came up rather rashly for you is to enable a toggle between manual and auto sync mode; |
Thank you!!! This kind of discussions really help me a lot.
It is actually intentional since all info about / attributes of the window can change at any moment, so it is necessary to query again or it may become totally obsolete and, therefore, useless in many use cases.
Just to be sure I understand your proposal, you suggest to add a new input parameter which allows to decide whether to return a preivously stored value (under the risk of being obsolete, but it's up to the user), or query for the updated one. Do you think this should be done for all values? I think that attributes like isActive, size or position are not as permanent over the time like others (as app name)... Should this behavior be limited to just some attributes? And, if so, which ones? Regarding this, there is a watchdog (use |
to replicate this problem, in Win11, write loop that runs both getactivewindow and getallwindows and check for existance of return of getactivewindow in getallwindonw, like the following piece
then press windows key to open windows search bar; assertion will fail.
The text was updated successfully, but these errors were encountered: