Capturing/Recognizing Text In Another Window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Brady Drummonds

    Capturing/Recognizing Text In Another Window

    Hello, everyone,

    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?

    Thanks,
    Scott

    --
    Remove ".nospam" from the user ID in my e-mail to reply via e-mail.


  • Tim Roberts

    #2
    Re: Capturing/Recognizing Text In Another Window

    "Scott Brady Drummonds" <scott.b.drummo nds.nospam@inte l.com> wrote:[color=blue]
    >
    >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?[/color]

    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.GetWin dowText to fetch the text inside it.
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    • JD

      #3
      Re: Capturing/Recognizing Text In Another Window

      I too am interested in this if anyone can shed some light. If I am
      understanding Scott's question, he is not refering to text that can be
      captured by GetWindowText or equivalent. For example, if the other
      program was a checkers game, how might one capture the screen so as to
      know where the checker pieces are?


      "Scott Brady Drummonds" <scott.b.drummo nds.nospam@inte l.com> wrote in message news:<blfg8b$no k$1@news01.inte l.com>...[color=blue]
      > Hello, everyone,
      >
      > 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?
      >
      > Thanks,
      > Scott[/color]

      Comment

      • Miki Tebeka

        #4
        Re: Capturing/Recognizing Text In Another Window

        Hello Scott,
        [color=blue]
        > 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?[/color]

        I'd use an automation program such as AutoIt
        (http://www.hiddensoft.com/AutoIt)
        to capture the scree usign ALT+PRTSC (there is an example in the help
        on how to do this). Then use MS Paint or whatever to save the image to
        the disc from the clipboard.

        From there on you can open the bitmap and do whatever you want (try
        PIL).

        HTH.
        Miki

        Comment

        • Bengt Richter

          #5
          Re: Capturing/Recognizing Text In Another Window

          On 15 Oct 2003 22:37:23 -0700, jeffrey123d@yah oo.com (JD) wrote:
          [color=blue]
          >To answer my own question for the benefit of others who are
          >interested, do it like this:
          >
          >import win32gui
          >import win32ui
          >
          >DC = win32ui.GetActi veWindow().GetD C()
          >MemDC = DC.CreateCompat ibleDC( None )
          >BitMap = win32ui.CreateB itmap()
          >BitMap.CreateC ompatibleBitmap (DC, 400, 400)
          >MemDC.SelectOb ject( BitMap )
          >MemDC.BitBlt(( 0,0), (400, 400), DC, (0,0), 13369376)
          >BitMap.SaveBit mapFile(MemDC, "c:\mybitmap.bm p")[/color]

          Just wondering what the BitBlt is doing with[color=blue][color=green][color=darkred]
          >>> hex(13369376)[/color][/color][/color]
          '0xcc0020'

          Regards,
          Bengt Richter

          Comment

          • Michael Geary

            #6
            Re: Capturing/Recognizing Text In Another Window

            > >MemDC.BitBlt(( 0,0), (400, 400), DC, (0,0), 13369376)
            [color=blue]
            > Just wondering what the BitBlt is doing with[color=green][color=darkred]
            > >>> hex(13369376)[/color][/color]
            > '0xcc0020'[/color]

            You can do a Google search on either the decimal or hex number to find out.
            But I'll tell you anyway... :-)

            BitBlt is a multipurpose function that takes a ROP (Raster OPeration) code
            that controls exactly what it does. 0xCC0020 is the ROP code SRCCOPY, i.e.
            do a simple copy from the source to the destination.

            -Mike


            Comment

            • Bengt Richter

              #7
              Re: Capturing/Recognizing Text In Another Window

              On Thu, 16 Oct 2003 15:48:02 -0700, "Michael Geary" <Mike@DeleteThi s.Geary.com> wrote:
              [color=blue][color=green][color=darkred]
              >> >MemDC.BitBlt(( 0,0), (400, 400), DC, (0,0), 13369376)[/color][/color]
              >[color=green]
              >> Just wondering what the BitBlt is doing with[color=darkred]
              >> >>> hex(13369376)[/color]
              >> '0xcc0020'[/color]
              >
              >You can do a Google search on either the decimal or hex number to find out.
              >But I'll tell you anyway... :-)
              >
              >BitBlt is a multipurpose function that takes a ROP (Raster OPeration) code
              >that controls exactly what it does. 0xCC0020 is the ROP code SRCCOPY, i.e.
              >do a simple copy from the source to the destination.
              >[/color]
              D'oh. I knew that. I need to sleep better...

              Regards,
              Bengt Richter

              Comment

              • News M Claveau /Hamster-P

                #8
                Re: Capturing/Recognizing Text In Another Window

                Hi !

                I obtain a traceback in line 4 : "win32ui : No windows is active." ???

                @-salutations
                --
                Michel Claveau


                Comment

                Working...