# https://docs.microsoft.com/en-us/windows/console/reading-input-buffer-events
use strict;
use warnings;
use Win32;
use Win32::Console;
my $console;
my @console_event;
unless ($console = new Win32::Console STD_INPUT_HANDLE)
{
print STDERR "\nSomething has gone wrong with the Win32::Console constructor: $!\n\n";
die;
}
$console -> Alloc ();
$console -> Mode (ENABLE_MOUSE_INPUT);
print "Perl version $^V running on ", join (" ", Win32::GetOSName), ".\n\n";
print "Your mouse has ", $console->MouseButtons(), " buttons.\n";
my $counter = 0;
while ($counter++ < 15)
{
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
{
sleep 1;
}
}
print "\nThe counter has reached $counter. Your input was not detected.\n";
print "Better luck after seeking the legendary wisdom of the Perl monks.\n";
####
Perl version v5.32.0 running on Win10 Build 18363 (64-bit).
Your mouse has 16 buttons.
##
##
A console event has been detected. Its attributes are the following:
1
1
1
75
37
107
32
Good job.