in reply to Win32::Event question
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32::Event question
by redss (Monk) on Jul 20, 2005 at 20:09 UTC | |
by ikegami (Patriarch) on Jul 20, 2005 at 20:26 UTC | |
by redss (Monk) on Jul 21, 2005 at 03:47 UTC | |
|
Re^2: Win32::Event question
by redss (Monk) on Jul 21, 2005 at 15:01 UTC | |
by ikegami (Patriarch) on Jul 21, 2005 at 15:12 UTC |