use strict; use warnings; use Time::HiRes qw (usleep); use Win32; use Win32::Console; my $console; my @console_event; undef $/; unless ($console = new Win32::Console STD_INPUT_HANDLE) { print STDERR "\nSomething has gone wrong with the Win32::Console constructor: $!\n\n"; die; } $console -> Mode (ENABLE_MOUSE_INPUT); print "Perl version $^V running on ", join (" ", Win32::GetOSName), ".\n\n"; print "Your mouse has ", $console->MouseButtons(), " buttons.\n\n"; print "Go ahead, make my day ...\n\n"; my $start_time = time (); my $when_to_stop_waiting = $start_time + 15; while (time () < $when_to_stop_waiting) { if ($console -> GetEvents ()) { @console_event = $console -> Input (); print "A console event has been detected. Its attributes are the following:\n\n"; print "$_\n" for @console_event; print "\nGood job.\n"; exit; # exit the program, do not fall through to that final print instruction } else { usleep 100; # sleep for 10 milliseconds, i.e. a hundredth of a second, to prevent # this program from getting into a really tight loop and crowding out # everyone else, but even without this usleep instruction the mouse # clicks are still not detected } } print "The time to stop waiting has been reached. Your input was not detected.\n"; print "Better luck after seeking the wisdom of the monks.\n";