in reply to Re: Unable to capture mouse events in Win32::Console
in thread Unable to capture mouse events in Win32::Console
I believe that the 1 second sleep idea is a "red herring" -> doesn't matter. All that means is that it will take at most one second for the keyboard event to be seen. A normal assumption would be that if you don't poll fast enough, you miss a character because apparently (not sure) that the event stack is only one character deep?
I did play around with the Properties of my standard command window. I turned off any of the normal fancy CTL-V or CTL-C off. But I haven't found the "magic formula" yet. In my testing with short programs, I am seeing that a right click causes the following program to "hang". When the program starts, hitting a normal key produces expected results, but a mouse click gets you nowhere!
I have seen other test programs fail to see the Right-Click. When the test program exits, I get the normal CTL-V behavior. Somehow the Mouse Click is not getting to the running test program and is buffered and presented to the command shell when the test program exits. The correct voo-doo for Console should be able to get this character (mouse click).
I am curious as to what others find. The sample code is complex and I am just trying to find a simple subset that works. This does not.
# https://docs.microsoft.com/en-us/windows/console/reading-input-buffe +r-events\ # reference Perl Monks: https://www.perlmonks.org/?node_id=1212227 use strict; use warnings; use Win32::Console; my $OUT = new Win32::Console(STD_OUTPUT_HANDLE); my $IN = new Win32::Console(STD_INPUT_HANDLE); $OUT->Write("Perl version $^V \n"); $OUT->Write("more text could go here\n\n"); my $n_buttons = $IN->MouseButtons(); $OUT->Write("Your mouse has $n_buttons buttons\n"); $IN->Mode(ENABLE_MOUSE_INPUT); my $counter = 0; while ($counter++ < 5) #5x time out for testing... { if (my @console_events = $IN -> Input ()) { $OUT->Write ("calling input method!\n"); # my @console_events = $IN -> Input (); ##not needed goof (COR +RECTION) $OUT->Write ("An Event was detected! number= ".@console_events. +"\n"); foreach my $event (@console_events) { $OUT->Write("event: $event\n"); } exit; # exit the program, do not fall through to that final + print instruction } else { sleep 1; #should be fine to poll 1x per second for testing... } } $OUT->Write("Timed out! Bummer!\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unable to capture mouse events in Win32::Console
by pryrt (Abbot) on Apr 26, 2022 at 13:54 UTC | |
by Marshall (Canon) on Apr 27, 2022 at 22:24 UTC | |
|
Re^3: Unable to capture mouse events in Win32::Console
by fireblood (Scribe) on Apr 26, 2022 at 04:13 UTC | |
by Marshall (Canon) on Apr 26, 2022 at 05:13 UTC | |
by Fletch (Bishop) on Apr 26, 2022 at 20:02 UTC | |
by fireblood (Scribe) on Apr 26, 2022 at 21:15 UTC |