How to get currently active window on Win32?

Wolfgang Strobl ws at mystrobl.de
Sun Dec 16 04:07:52 EST 2001


On Sat, 15 Dec 2001 17:53:49 -0800 (PST), David Brady
<daves_spam_dodging_account at yahoo.com> wrote :

>More win32all questions... is it possible to get the
>handle of the window that currently has the focus? 
>win32gui.GetActiveWindow() fails because I'm looking
>for a window outside the process of my Python script.

E:\>python
ActivePython 2.1.1, build 212 (ActiveState)
Python 2.1.1 (#20, Jul 26 2001, 11:38:51) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import win32gui
>>> import time
>>> for x in range(10):
...     time.sleep(1)
...     print x, win32gui.GetWindowText(win32gui.GetForegroundWindow())
...
0 cmd - python
1 cmd - python
2 (Untitled) * SciTE
3 (Untitled) * SciTE
4 ActivePython Documentation
5 ActivePython Documentation
6 PythonWin
7 PythonWin
8 PythonWin


-- 
Thank you for observing all safety precautions



More information about the Python-list mailing list