Bug in Win32::Clipboard::WaitForChange() ?

J

jl_post

Hi,

I've used the Win32::Clipboard module for quite some time, but I've
never been able to get the ::WaitForChange() method to work properly.
What I mean is, when I run the following program:


#!/usr/bin/perl

use strict;
use warnings;

$| = 1; # autoflush STDOUT

use Win32::Clipboard;
print "Waiting for change in clipboard...\n";

my $CLIP = Win32::Clipboard();
$CLIP->WaitForChange();

print "\nClipboard has changed!\n\n";

__END__


the program prints the messages and ends instantly, without ever
waiting for new content to be copied to the clipboard buffer.

If memory serves, I've encountered this problem on both ActiveState
perl 5.8 on Windows Vista, and now on Strawberry Perl 5.10 on Windows
7. (Also, $Win32::Clipboard::VERSION is 0.55 .)

So is the fact that ::WaitForChange() doesn't actually wait for a
change in the system clipboard a bug, or am I using it wrong? (And if
I'm using it wrong, what is the proper way to wait until the clipboard
has changed?)

Thanks,

-- Jean-Luc
 
B

Brian Helterline

Hi,

I've used the Win32::Clipboard module for quite some time, but I've
never been able to get the ::WaitForChange() method to work properly.
What I mean is, when I run the following program:


#!/usr/bin/perl

use strict;
use warnings;

$| = 1; # autoflush STDOUT

use Win32::Clipboard;
print "Waiting for change in clipboard...\n";

my $CLIP = Win32::Clipboard();
$CLIP->WaitForChange();

according to the docs, this function returns 1 when the clipboard
changes, undef on error. You might want to check the return value.
 
C

C.DeRykus

Hi,

   I've used the Win32::Clipboard module for quite some time, but I've
never been able to get the ::WaitForChange() method to work properly.
What I mean is, when I run the following program:

#!/usr/bin/perl

use strict;
use warnings;

$| = 1;  # autoflush STDOUT

use Win32::Clipboard;
print "Waiting for change in clipboard...\n";

my $CLIP = Win32::Clipboard();
$CLIP->WaitForChange();

print "\nClipboard has changed!\n\n";

__END__

the program prints the messages and ends instantly, without ever
waiting for new content to be copied to the clipboard buffer.

   If memory serves, I've encountered this problem on both ActiveState
perl 5.8 on Windows Vista, and now on Strawberry Perl 5.10 on Windows
7.  (Also, $Win32::Clipboard::VERSION is 0.55 .)

   So is the fact that ::WaitForChange() doesn't actually wait for a
change in the system clipboard a bug, or am I using it wrong?  (And if
I'm using it wrong, what is the proper way to wait until the clipboard
has changed?)

If your script calls WaitForChange() again, it
actually waits as you'd expect. The constructor
allows specifying an initial value to compare
but, even if set there, the first call doesn't
wait. Seems buggy to me too.



my $CLIP = Win32::Clipboard("Foo");
print "clipboard initially: ",
$CLIP->Get(), length $CLIP->Get(), "\n";
print "waiting for change...\n";
$CLIP->WaitForChange();
print "clipboard has changed: ",
$CLIP->Get(), length $CLIP->Get(), "\n";

# Now waits until changed...
print "\nwaiting for change again...\n";
$CLIP->WaitForChange();
print "clipboard has changed: ",
$CLIP->Get(), length $CLIP->Get(), "\n";

---> clipboard initially: Foo3
waiting for change...
clipboard has changed: Foo3

waiting for change again...
 
J

jl_post

If your script calls WaitForChange() again, it
actually waits as you'd expect.

Thanks, Charles. That does help somewhat. I had never tried
calling WaitForChange() a second time, so I never discovered this work-
around before.

Thanks again,

-- Jean-Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top