in reply to Copy text from a window

Adapted from BrowserUk's snippet.

This will print the text from any open Notepad window.
See Win32::GuiTest and Win32::Clipboard.

#!/usr/bin/perl use warnings; use strict; use Win32::GuiTest qw[FindWindowLike SendKeys SetForegroundWindow]; use Win32::Clipboard; my $clip = Win32::Clipboard(); for my $w (FindWindowLike(undef, qr{ - Notepad$}, undef, undef, undef) +){ SetForegroundWindow($w); SendKeys(q{^A^C}); print $clip->Get(); }
update1: removed a debugging print statement
update2: fixed link

Replies are listed 'Best First'.
Re^2: Copy text from a window
by Jon99 (Initiate) on Mar 03, 2009 at 16:34 UTC
    Thnx, it really works for Notepad. But what I want to do is to copy from an application, that has a child-window with text in it. The coping of this text is limited with the copy/paste procedure.
        This tutorial was very helpful. This is the code I wrote:
        use Win32::GuiTest qw( FindWindowLike WMGetText ); use strict; use warnings; my @whnds = FindWindowLike( undef, "^Fjalori elektronik shpjegues" + ); if( !@whnds ){ die "Cannot find window with title/caption Fjalori\n"; }else{ printf( "Window handle of calculator application is %x\n", $wh +nds[ 0 ] ); } my $edit_ctrl_id = 600; #Edit window, 258 Hex my @edit = FindWindowLike( $whnds[ 0 ], undef, "^AEditCtl32", $edi +t_ctrl_id ); if( !@edit ){ die "Cannot find window handle for Edit control\n"; }else{ printf( "Edit window handle is %x\n", $edit[ 0 ] ); } my $result = WMGetText( $edit[ 0 ] ); print $result;
        It runs OK, but there is nothing in the output. It seems that is so because of the window class "AEditCtl32" where I am trying to read. Does it make sense to continue in this direction, or should I try working with buffers?