Detecting keypress when window isn't in focus
- From: Chris Wilkins <chris.wilkins1@xxxxxxxxx>
- Date: Fri, 25 Jul 2008 00:53:08 -0700 (PDT)
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?
.
- Follow-Ups:
- Re: Detecting keypress when window isn't in focus
- From: Jürgen Exner
- Re: Detecting keypress when window isn't in focus
- From: zentara
- Re: Detecting keypress when window isn't in focus
- Prev by Date: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.8 $)
- Next by Date: Re: Detecting keypress when window isn't in focus
- Previous by thread: FAQ 4.5 How do I convert between numeric representations/bases/radixes?
- Next by thread: Re: Detecting keypress when window isn't in focus
- Index(es):
Relevant Pages
|