http://qs321.pair.com?node_id=11143285

fireblood has asked for the wisdom of the Perl Monks concerning the following question:

Dear wise ones,

I've been trying to capture mouse events using Win32::Console and after having done an advanced Google search on perlmonks, have not been able to find an answer. My code is the following:

# https://docs.microsoft.com/en-us/windows/console/reading-input-buf +fer-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::Conso +le 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 attribu +tes are the following:\n\n"; print "$_\n" for @console_event; print "\nGood job.\n"; exit; # exit the program, do not fall through to t +hat 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 monk +s.\n";

The initial output from the above code is

Perl version v5.32.0 running on Win10 Build 18363 (64-bit). Your mouse has 16 buttons.
While this code is running, if I press on any key, I get the following output:
A console event has been detected. Its attributes are the following: 1 1 1 75 37 107 32 Good job.

The value of "1" in the first array element indicates that the event type is keyboard input. When mouse input is captured, the first array element should have a value of "2". However, while this program is running, I can click on the console window endlessly and the mouse click is not detected. I end up falling through to the final consolation message after the end of looping.

What am I missing in how I'm setting this up to enable capturing of mouse events?

Thank you.