Is it impossible to get notifed as soon as a new window is created? #61
Replies: 1 comment
-
Hi! In Windows, I think it's possible, but not using Python. I think to remember you had to inject a hook to an OS process, using C++, and I believe it has to be done from a separate DLL. Take a look to this and this. In Linux and macOS, it's definitely not possible. At least not that I know. Using
To avoid point 1, create a separate thread which will be in charge of watching windows in a loop, passing a callback that the thread may invoke to notify main process when a new window is created. To improve point 2, reduce the wait time of the thread loop (in my system, getAllWindows() takes 0.0014870166778564453 seconds, although it highly depends on your system specs and how many open windows you have). Take a look to this (it's a quick and dirty adaptation of something similar I have developed to control monitors plugged to / unplugged from system):
This script reacts to new windows created in up to 0.1 seconds, and is consuming 0.3% of my CPU. |
Beta Was this translation helpful? Give feedback.
-
#58 I got answered that I need to call
getAllWindows
periodically.Maybe I have no knowledge about the structure of Windows's event system.
But I think the current implementation is not efficient.
Can't we hook some API so that we can get notified as soon as a new window is created?
Beta Was this translation helpful? Give feedback.
All reactions