Detecting keypress when window isn't in focus



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?
.



Relevant Pages

  • Re: Report in FM 6 or 7
    ... achieve this report format will have to be done via scripting. ... but they will simplify the script and Sort Order. ... End Loop ... The normal 'Dancer' field is used so that if there are more than one ...
    (comp.databases.filemaker)
  • Re: recreate database script not work
    ... I got a script which is supposed to regenerate database systax. ... REM gen_dbse_9.sql ... end loop; ...
    (comp.databases.oracle.server)
  • Re: Loop Problem (At Least I think)
    ... If there are no images matching the product ... "" Then" statement (the one below the loop, outside of it), is this just ... >> script to finish. ... > 2) Read the database table and acess the dictionary object for the ...
    (microsoft.public.scripting.vbscript)
  • Re: How to set up a global variable in a sub-routine?
    ... the 'global variables' are more like constants ... ... single script, I need a way to tell it only once where the file is and ... So, if you construct a loop with a loop variable, you ... >programmers avoid global variables completely. ...
    (perl.beginners)
  • Re: Array, foreach problem
    ... I'm stuck on using an array to determine the out come of a foreach loop. ... The script is below. ... Shlomi Fish http://www.shlomifish.org/ ...
    (perl.beginners)