Discussion:
Bug in Win32::Clipboard::WaitForChange() ?
(too old to reply)
j***@hotmail.com
2010-10-04 18:11:32 UTC
Permalink
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
Brian Helterline
2010-10-05 03:30:09 UTC
Permalink
Post by j***@hotmail.com
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.
#!/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.
Post by j***@hotmail.com
print "\nClipboard has changed!\n\n";
__END__
C.DeRykus
2010-10-05 04:56:58 UTC
Permalink
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.
#!/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...


--
Charles DeRykus
j***@hotmail.com
2010-10-11 15:34:41 UTC
Permalink
Post by C.DeRykus
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

Loading...