Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Unable to capture mouse events in Win32::Console

by vr (Curate)
on Apr 29, 2022 at 18:45 UTC ( #11143452=note: print w/replies, xml ) Need Help??


in reply to Re: Unable to capture mouse events in Win32::Console
in thread Unable to capture mouse events in Win32::Console

I feel partly responsible for confusion and code re-writes caused by my words that "GetEvents and sleep are not required". I don't know if you indeed tried to exclude both to find timeout never occurs if user is inactive; then restored just "peeking" into the queue (GetEvents) to detrimental effect, and finally restored the original. Maybe this timeout is crucial to your application. Maybe the above never happened, it's just the (wrong) idea of

GetEvents returned just a single scalar ... would be more efficient

Maybe you tried to timeout through alarm (I think it is somewhere in FAQ) to find it doesn't work with blocking I/O on Windows. Maybe I'm partially or totally wrong, you are not interested in "things async", peeking/blocking, etc. Code finally working as desired is important (which is absolutely right!), goal achieved. Well, so it's to my amusement and sleep-not-really-OK bias I found that timed-out Win32::Console::Input can be done like this:

use strict; use warnings; use feature 'say'; use Win32::Console; use Win32::IPC 'wait_any'; use Time::HiRes 'time'; my $IN = Win32::Console-> new( STD_INPUT_HANDLE ); my $max = 15; my $count = 0; my $t = time + $max; while ( wait_any @{[ $IN ]}, 1000 * ( $t - time )) { my @ev = $IN-> Input; say "Ah ah ah, you didn't press the magic key <--- @ev"; ++ $count } say $count ? "Enough, I'm tired! $count events in $max seconds!" : "You failed to press ANY key in $max seconds! Read my FAX!!!";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11143452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-08-18 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?