Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Screen capture on Windows

by jmcnamara (Monsignor)
on May 20, 2004 at 20:50 UTC ( #355073=snippet: print w/ replies, xml ) Need Help??

Description: A simple method of doing a screen capture on Windows.

For a more flexible approach see Win32::Screenshot



#!/usr/bin/perl -w

use strict;
use Win32::Clipboard;
use Win32::GuiTest 'SendKeys';


# Send "Print Screen" key to Windows.
SendKeys('{PRTSCR}');


# Get the image from the clipboard.
my $screen = Win32::Clipboard::GetBitmap()
             or die "No image captured: $!\n";


# Print the image to a file.
open    BITMAP, "> screen.bmp" or die "Couldn't open bitmap file: $!\n
+";
binmode BITMAP;
print   BITMAP $screen;
close   BITMAP;

__END__



#
# Or to capture a specific Window:
#


#!/usr/bin/perl -w

use strict;
use Win32::Clipboard;
use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys);


# Find a specific Window
my @windows = FindWindowLike(0, qr/^Microsoft Excel/, qr/^XLMAIN$/);

for (@windows) {
    SetForegroundWindow($_);
    SendKeys('%{PRTSCR}'); # Alt Print Screen
}


# Get the image from the clipboard.
my $screen = Win32::Clipboard::GetBitmap()
             or die "No image captured: $!\n";


# Print the image to a file.
open    BITMAP, "> screen.bmp" or die "Couldn't open bitmap file: $!\n
+";
binmode BITMAP;
print   BITMAP $screen;
close   BITMAP;

__END__

Comment on Screen capture on Windows
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://355073]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2014-10-25 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls