I can think of three ways.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.