Hi Anonymous, thanks for replying so quickly. Actually, I had seen that sample code previously, and had downloaded and run it, and found that although it displayed amazing graphics, it too did not respond to my mouse clicks. I also noticed that it did not have a $console -> Alloc () instruction anywhere, which I initially thought might be why neither it nor my program responded to mouse events, because I did not have a $console -> Alloc either. However, when I added a $console -> Alloc () instruction to my code, the window in which my program was running would instantly vanish as soon as the $console -> Alloc instruction was reached. So I fiddled with $console -> Free () with it for a while, to no avail, and finally removed the $console -> Alloc instruction again.
I have now revised my code to eliminate the 1-second sleep. By commenting one instruction or not, I can make it sleep only a hundredth of a second or not sleep at all, with the results being the same, viz. no mouse events are detected. This is the revised code:
use Time::HiRes qw (usleep);
unless ($console = new Win32::Console STD_INPUT_HANDLE)
print STDERR "\nSomething has gone wrong with the Win32::Conso
+le constructor: $!\n\n";
$console -> Mode (ENABLE_MOUSE_INPUT);
print "Perl version $^V running on ", join (" ", Win32::GetOSName), ".
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 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
usleep 100; # sleep for 10 milliseconds, i.e. a
+hundredth of a second, to prevent
# this program from getting into a r
+eally tight loop and crowding out
# everyone else, but even without th
+is usleep instruction the mouse
# clicks are still not detected
print "The time to stop waiting has been reached. Your input was not d
print "Better luck after seeking the wisdom of the monks.\n";
When I run this revised version and press any key, the following is generated:
Go ahead, make my day ...
A console event has been detected. Its attributes are the following:
But as before, I can click on the mouse all night, and this is what is generated:
Perl version v5.32.0 running on Win10 Build 18363 (64-bit).
Your mouse has 16 buttons.
Go ahead, make my day ...
The time to stop waiting has been reached. Your input was not detected
Better luck after seeking the wisdom of the monks.
I've thought about re-writing my application in Win32::GUI but it would involve writing a lot more code creating and managing the window entirely within the program, not just hooking into a pre-existing console as with Win32::Console.