C
Chris Wilkins
I have a script which loops forever and I need a way to break out of
the loop with a keypress. I can do this with the script below and it
works fine, my problem is that if I take the focus away from the
command window that the script is running in, the keypress isn't
recognised and the loop doesn't end.
#!/usr/bin/perl -l
use strict;
use warnings;
use Win32::GuiTest qw/:ALL/;
use Term::ReadKey;
my $i = 0;
while (1)
{
ReadMode(3);
my $char = ReadKey(-1);
if ($char eq 'q')
{
last;
}
print $i;
sleep 1;
$i++;
}
Is there a way (with Term::ReadKey or anything else) of detecting a
keypress when the script window does not have focus?
the loop with a keypress. I can do this with the script below and it
works fine, my problem is that if I take the focus away from the
command window that the script is running in, the keypress isn't
recognised and the loop doesn't end.
#!/usr/bin/perl -l
use strict;
use warnings;
use Win32::GuiTest qw/:ALL/;
use Term::ReadKey;
my $i = 0;
while (1)
{
ReadMode(3);
my $char = ReadKey(-1);
if ($char eq 'q')
{
last;
}
print $i;
sleep 1;
$i++;
}
Is there a way (with Term::ReadKey or anything else) of detecting a
keypress when the script window does not have focus?