Capturing/Recognizing Text In Another Window

Tim Roberts timr at probo.com
Thu Oct 2 05:31:22 CEST 2003


"Scott Brady Drummonds" <scott.b.drummonds.nospam at intel.com> wrote:
>
>I'd like to write a Python program that could capture the contents of
>another Windows program and analyze the resultant bitmap.  First, I have no
>idea how to capture another window.  Second, I'm not even certain if this
>graphical problem is a Python issue or a Windows issue.
>
>Can anyone offer me some guidance on this?

If the thing you are trying to read is a text control, such as what Notepad
presents, you don't have to analyze a bitmap: you can fetch the text as a
string.  You'll have to use the Windows API to do it, so you'll want to
read up on the win32gui and win32ui modules.

First, use a tool like spyxx to examine the app you want to scrape.  Find
the ID of the control you want.

Now, fromm Python, you can use FindWindow or EnumWindows to find the
top-level app you want to manipulate.  Then, you can use GetDlgItem to
fetch the window handle of the control with your desired ID.  Then, use
win32gui.GetWindowText to fetch the text inside it.
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list