Win32-Clipboard

 view release on metacpan or  search on metacpan

Clipboard.pm  view on Meta::CPAN

package Win32::Clipboard;
#######################################################################
#
# Win32::Clipboard - Interaction with the Windows clipboard
#
# Version: 0.58
# Author: Aldo Calpini <dada@perl.it>
#
# Modified by: Hideyo Imazu <himazu@gmail.com>
#
#######################################################################

require Exporter;
require DynaLoader;

Clipboard.pm  view on Meta::CPAN

    my $result = Win32::Clipboard::Set($value) if defined($value);
    return bless($self, "Win32::Clipboard");
}

1;

__END__

=head1 NAME

Win32::Clipboard - Interaction with the Windows clipboard

=head1 SYNOPSIS

    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";


=head1 DESCRIPTION

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:

=over 4

=item * text (C<CF_TEXT>)

The clipboard contains some text; this is the B<only> format you can
use to set clipboard data; you get it as a single string.

Example:

    $text = Win32::Clipboard::GetText();
    print $text;

=item * bitmap (C<CF_DIB>)

The clipboard contains an image, either a bitmap or a picture copied
in the clipboard from a graphic application. The data you get is a
binary buffer ready to be written to a bitmap (BMP format) file.

Example:

    $image = Win32::Clipboard::GetBitmap();
    open    BITMAP, ">some.bmp";
    binmode BITMAP;
    print   BITMAP $image;
    close   BITMAP;

=item * list of files (C<CF_HDROP>)

The clipboard contains files copied or cutted from an Explorer-like
application; you get a list of filenames.

Example:

    @files = Win32::Clipboard::GetFiles();
    print join("\n", @files);

=back

=head2 REFERENCE

All the functions can be used either with their full name
(eg. B<Win32::Clipboard::Get>) or as methods of a C<Win32::Clipboard>
object.  For the syntax, refer to L</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;

=over 4

=item Empty()

Empty the clipboard.

=item EnumFormats()

Returns an array of identifiers describing the format for the data
currently in the clipboard. Formats can be standard ones (described in
the L</CONSTANTS> section) or application-defined custom ones. See
also IsFormatAvailable().

=item Get()

Returns the clipboard content; note that the result depends on the
nature of clipboard data; to ensure that you get only the desired
format, you should use GetText(), 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.

=item GetAs(FORMAT)

Returns the clipboard content in the desired FORMAT (can be one of the
constants defined in the L</CONSTANTS> section or a custom
format). Note that the only meaningful identifiers are CF_TEXT,
CF_UNICODETEXT, CF_DIB and CF_HDROP; any other format is treated as a
string.

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);

=item GetBitmap()

Returns the clipboard content as an image, or C<undef> on errors.

=item GetFiles()

Returns the clipboard content as a list of filenames, or C<undef> on
errors.

=item GetFormatName(FORMAT)

Returns the name of the specified custom clipboard format, or C<undef>
on errors; note that you cannot get the name of the standard formats
(described in the L</CONSTANTS> section).

=item GetText()

Returns the clipboard content as a string, or C<undef> on errors.

=item IsBitmap()

Returns a boolean value indicating if the clipboard contains an image.
See also GetBitmap().

=item IsFiles()

Returns a boolean value indicating if the clipboard contains a list of
files. See also GetFiles().

=item IsFormatAvailable(FORMAT)

Checks if the clipboard data matches the specified FORMAT (one of the
constants described in the L</CONSTANTS> section); returns zero if the
data does not match, a nonzero value if it matches.

=item IsText()

Returns a boolean value indicating if the clipboard contains text.
See also GetText().

=item Set(VALUE)

Set the clipboard content to the specified string.

=item WaitForChange([TIMEOUT])

This function halts the script until the clipboard content changes. If
you specify a C<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, C<undef> on errors.

=back

=head2 CONSTANTS

These constants are the standard clipboard formats recognized by
Win32::Clipboard:

    CF_TEXT             1
    CF_DIB              8
    CF_HDROP            15

The following formats are B<not recognized> by Win32::Clipboard; they
are, however, exported constants and can eventually be used with the
EnumFormats(), IsFormatAvailable() and GetAs() functions:

Clipboard.xs  view on Meta::CPAN

/*
#######################################################################
#
# Win32::Clipboard - Interaction with the Windows clipboard
#
# Version: 0.58
# Created: 19 Nov 96
# Author: Aldo Calpini <dada@perl.it>
#
# Modified: 24 Jul 2004
# By: Hideyo Imazu <h@imazu.net>
#
#######################################################################
 */

Clipboard.xs  view on Meta::CPAN



void
WaitForChange(...)
PPCODE:
    DWORD cause;
	DWORD timeout;

    if(hThread == NULL) {
#ifdef WIN32__CLIPBOARD__DEBUG
        printf("XS(WaitForChange): Starting the clipboard viewer...\n");
#endif
        hThread = StartClipboardViewer();
    }

    // set the event to be waited for
    ResetEvent(hEvt);

	timeout = INFINITE;

	if(items == 1 && !SvROK(ST(0))) { timeout = (DWORD)SvIV(ST(0)); }

META.yml  view on Meta::CPAN

--- #YAML:1.0
name: Win32-Clipboard
abstract: Interaction with the Windows clipboard
version: 0.58
author:
  - Aldo Calpini <dada@perl.it>
  - Hideyo Imazu <himazu@gmail.com>
  - Jan Dubois <jand@activestate.com>
license: perl
requires: 
  perl: 5.006
resources:
  license: http://dev.perl.org/licenses/
  repository: https://github.com/jandubois/win32-clipboard
meta-spec:
   version: 1.3
   url: http://module-build.sourceforge.net/META-spec-v1.3.html
generated_by: Jan Dubois

README  view on Meta::CPAN

#######################################################################
#
# Win32::Clipboard - Interaction with the Windows clipboard
#
# Author: Aldo Calpini <dada@perl.it>
# Modified by: Hideyo Imazu <h@imazu.net>
# Version: 0.58
# Info:
#       http://dada.perl.it
#       http://www.perl.com/CPAN/authors/Aldo_Calpini
#
#######################################################################

DESCRIPTION

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 getting clipboard data:

    - simple text
    - bitmaps
    - list of files

...and only simple text for putting data to the clipboard.

SYNOPSIS

    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";


samples/bitmap.pl  view on Meta::CPAN


if(Win32::Clipboard::IsBitmap) {
	$BUFFER = 
	open BMP, ">test.bmp";
	binmode BMP;
	print BMP Win32::Clipboard::Get();
	close BMP;
	undef $BUFFER;
	print "data written to test.bmp\n";
} else {
	print "clipboard does not contain a bitmap!\n";
}

samples/monitor.pl  view on Meta::CPAN

use blib;
use Win32::Clipboard;

print <<EOP;

  copy "quit" to the clipboard to quit!

EOP

$C = Win32::Clipboard();
$C->Empty();
LOOP:
while ($C->Get() ne "quit") {
	$whathappened = $C->WaitForChange(10000);
	if(not defined $whathappened) {
		die "error in WaitForChange: $^E\n";

samples/test-tie.pl  view on Meta::CPAN

use Win32::Clipboard;

tie $clip, 'Win32::Clipboard';

print "Clipboard Content:\n\n$clip\n";

tied($clip)->Empty();

$clip = "ciao mondo!";

print "\nLook at your clipboard now!\n\n";

samples/test.pl  view on Meta::CPAN

use Win32::Clipboard;

$clip = Win32::Clipboard;

print "Clipboard Content:\n\n", $clip->Get, "\n";

$clip->Empty();

$clip->Set("ciao mondo!");

print "\nLook at your clipboard now!\n\n";



( run in 2.500 seconds using v1.01-cache-2.11-cpan-84e82930d8c )