1) Poll the keyboard
use Win32::Event; # $end_time will be up to a second too short without Time::HiRes. use Time::HiRes; my $event = new Win32::Event( 0, 0, "MyEvent.$$" ); my $abort = 0; while (!$abort) { my $end_time = time + 1; # wait 1 sec while (1) { $rv = $event->wait(50); # Poll keyboard every 50ms if ($rv) { print "called via event\n"; last; } if (...a key is pressed...) { print "aborted by user\n"; $abort = 1; last; } if (time > $end_time) { print "timeout\n"; last; } } }
2) Have a second thread monitor the keyboard. When a key is pressed, raise a "user aborted" event. The original thread now has to wait on two events (the original one and the "user aborted" event), but there's a function to do that.
3) Use POE. I haven't checked if it can help you here, but I bet it can.
In reply to Re: Win32::Event question
by ikegami
in thread Win32::Event question
by redss
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |