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.


In reply to Unable to capture mouse events in Win32::Console by fireblood

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.