Michael B. Wright wrote:
>
>>-----Original Message-----
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED]]On Behalf Of Dietmar
>>Thal
>>Sent: Tuesday, July 02, 2002 9:53 AM
>>To: Activeperl
>>Subject: print screen with perl
>>
>>
>>hello,
>
>
> Hello
>
>
>>i am quite new to system related programming with perl,
>>and i am looking for a possibility to print the current
>>screen to the clipboard as 'print screen' would do.
>>i suppose the truth lies within Win32::OLE,
>
>
> Sadly, there is neither truth or beauty in OLE ;-) While there is probably
> some way to get a screen-dump w/ OLE, it is probably overkill. Everything
> you need is in the Win32 API. You "find" your window and use GDI's device
> context handling functions to copy the bitmap. That isn't necessary,
> however, if a simple "printscrn" would do. If so, try something like
> this...
>
> (sshot.wsf follows)
>
> <?xml version="1.0" standalone="yes"?>
> <?job error="yes" debug="no" ?>
> <package>
> <job id="default">
> <runtime>
> <description><![CDATA[Script (sshot.wsf) to take a
> screenshot]]></description>
> <example><![CDATA[sshot.wsf]]></example>
> </runtime>
> <script language="PerlScript">
> <![CDATA[
>
> use Win32::API; # if you don't already have it, you should get it....
> # try: "ppm install --location=http://dada.perl.it/PPM Win32::API"
>
> $push_key = new Win32::API("user32", "keybd_event", 'IINP', 'V');
> die "Can't import user32.dll: $!\n" if(not defined $push_key);
> $push_key->Call(0x2C, 0x45, 0x01, 0); #simulate a "printscrn" key press
> $push_key->Call(0x2C, 0x45, 0x03, 0); # & release
>
> #save the bitmap in the clipboard to a file...
> use Win32::Clipboard;
> $image = Win32::Clipboard::GetBitmap();
> open(BITMAP, ">sshot.bmp") or die "$!";
> binmode(BITMAP);
> print BITMAP $image;
> close(BITMAP);
>
> ]]>
> </script>
> </job>
> </package>
>
>
>>but how can
>>i recognize, from which executable or dll i have to extract
>>which function to provide this?
>
>
> Familiarity with the Windows API. There is ample documentation on
> Microsoft's website.
This seems to work from commandline:
#!perl -w --
use strict;
use Win32::API;
my $push_key = new Win32::API("user32", "keybd_event", [qw(I I N P)], 'V') or
die "keybd_event: " . Win32::FormatMessage (Win32::GetLastError ());
use constant VK_SNAPSHOT => 0x2C;
use constant KEYEVENTF_EXTENDEDKEY => 0x01;
use constant KEYEVENTF_KEYUP => 0x02;
my $bVk = VK_SNAPSHOT;
my $bScan = 0x01; # backwards from docs: 1=screen; 0=window
# PRINT SCR scan code for 102 keybd => E0 2A E037
# 2A or 37 gets window
my $dwFlags = KEYEVENTF_EXTENDEDKEY;
my $dwExtraInfo = 0;
$push_key->Call($bVk, $bScan, $dwFlags, 0); # simulate a "printscrn" key press
# the release seems to not be needed
#$dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
#$push_key->Call($bVk, $bScan, $dwFlags, 0); # & release
use Win32::Clipboard;
my $file = 'screendump.bmp';
my $image = Win32::Clipboard::GetBitmap ();
open BITMAP, ">$file" or die "Error creating $file: $!";
binmode BITMAP;
print BITMAP $image;
close BITMAP;
__END__
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs