#! perl -slw use strict; use Win32::GuiTest qw[FindWindowLike SetForegroundWindow SendKeys]; use Win32::Clipboard; my $clip = Win32::Clipboard->new(); my @windows = FindWindowLike( 0, $ARGV[ 0 ] ); #Find it die "Couldn't find window '$ARGV[ 0 ]" unless @windows; for (@windows) { SetForegroundWindow( $_ ); # Make it active sleep 1; ## Send the Alt-print screen key sequence to copy ## the active window to the clipboard SendKeys("%{PRTSCR}"); } my $fname = "$ARGV[ 0 ]-@{[ time() ]}"; print $fname; if( my $bitmap = $clip->GetBitmap() ) { local $\; my $bmpfile = $fname . '.bmp'; open my $bmp, '>', $bmpfile or die $!; binmode $bmp; print $bmp $bitmap; close $bmp; print "Bitmap written to $bmpfile\n"; system "bmp2png $bmpfile"; print "Converted to $fname.png"; } else { die "Couldn't get bitmap from clipboard"; } __END__ C:\test>screengrab Opera Opera-1265829469 Bitmap written to Opera-1265829469.bmp OK Opera-12658294 oooooooooooooooooooooooooooooooooooooooooooooooooooo Converted to Opera-1265829469.png