Win32::Clipboard - Interaction with the Windows clipboard |
Win32::Clipboard - Interaction with the Windows clipboard
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
print "Clipboard contains: ", $CLIP->Get(), "\n";
$CLIP->Set("some text to copy into the clipboard");
$CLIP->Empty();
$CLIP->WaitForChange(); print "Clipboard has changed!\n";
This module lets you interact with the Windows clipboard: you can get its content, set it, empty it, or let your script sleep until it changes. This version supports 3 formats for clipboard data:
CF_TEXT
)Example:
$text = Win32::Clipboard::GetText(); print $text;
CF_DIB
)Example:
$image = Win32::Clipboard::GetBitmap(); open BITMAP, ">some.bmp"; binmode BITMAP; print BITMAP $image; close BITMAP;
CF_HDROP
)Example:
@files = Win32::Clipboard::GetFiles(); print join("\n", @files);
All the functions can be used either with their full name
(eg. Win32::Clipboard::Get) or as methods of a Win32::Clipboard
object. For the syntax, refer to SYNOPSIS above. Note also that
you can create a clipboard object and set its content at the same time
with:
$CLIP = Win32::Clipboard("blah blah blah");
or with the more common form:
$CLIP = new Win32::Clipboard("blah blah blah");
If you prefer, you can even tie the Clipboard to a variable like this:
tie $CLIP, 'Win32::Clipboard';
print "Clipboard content: $CLIP\n";
$CLIP = "some text to copy to the clipboard...";
In this case, you can still access other methods using the tied()
function:
tied($CLIP)->Empty; print "got the picture" if tied($CLIP)->IsBitmap;
Empty()
EnumFormats()
Get()
GetBitmap()
or GetFiles()
instead. Get()
is in fact implemented as:
if( IsBitmap() ) { return GetBitmap(); } elsif( IsFiles() ) { return GetFiles(); } else { return GetText(); }
See also IsBitmap(), IsFiles(), IsText(), EnumFormats()
and
IsFormatAvailable()
to check the clipboard format before getting data.
GetAs(FORMAT)
If CF_UNICODETEXT is used, then binary Unicode data is returned. A perl unicode string can be generated as follows:
$text = $clip->GetAs(CF_UNICODETEXT); $text = Encode::decode("UTF16-LE", $text);
GetBitmap()
undef
on errors.
GetFiles()
undef
on
errors.
GetFormatName(FORMAT)
undef
on errors; note that you cannot get the name of the standard formats
(described in the CONSTANTS section).
GetText()
undef
on errors.
IsBitmap()
IsFiles()
IsFormatAvailable(FORMAT)
IsText()
Set(VALUE)
WaitForChange([TIMEOUT])
TIMEOUT
value (in milliseconds), the function will
return when this timeout expires, even if the clipboard hasn't
changed. If no value is given, it will wait indefinitely. Returns 1 if
the clipboard has changed, undef
on errors.
These constants are the standard clipboard formats recognized by Win32::Clipboard:
CF_TEXT 1 CF_DIB 8 CF_HDROP 15
The following formats are not recognized by Win32::Clipboard; they
are, however, exported constants and can eventually be used with the
EnumFormats(), IsFormatAvailable()
and GetAs()
functions:
CF_BITMAP 2 CF_METAFILEPICT 3 CF_SYLK 4 CF_DIF 5 CF_TIFF 6 CF_OEMTEXT 7 CF_PALETTE 9 CF_PENDATA 10 CF_RIFF 11 CF_WAVE 12 CF_UNICODETEXT 13 CF_ENHMETAFILE 14 CF_LOCALE 16
Version 0.52 was released by Hideyo Imazu <himazu@gmail.com>.
Aldo Calpini <dada@perl.it> was the former maintainer.
Original XS porting by Gurusamy Sarathy <gsar@cpan.org>.
Win32::Clipboard - Interaction with the Windows clipboard |