Hello dear monasterians,
I'm trying to write a script that will do a specific function when the computer shell be untouched for 15 minutes. I was wondering how to do that because after reading
Win32::Process i couldn't find there anything that tells for 'how long' the computer been idle (just the timeout when to die). I found in the following post a small code to use
Win32::API but it is unclear to me,
Checking that local Windows machine is idle, and the monasterian that posted that code wasn't in the monastery for 4 years so there's no-one to ask in person.
I'm trying to do something that would look like :
#!/usr/bin/perl -w
use strict;
# use some Win32 module for the task
# the checking if anything been pressed logically combined with perl s
+eems to me to look like
my $trials = 20; # for 10 minutes
while ($trials) {
if (("mouse moved") or ("any key pressed")) {
$trials = 20; # start the countdown all over again
} else {
$trials--; #decrease a trial
sleep(30); #wait half a minute
}
}
#now that $trials equals to 0 - therefore nothing been pressed for 10
+minutes (20 halves of a minute {for better results})
doMyFunc($var1, $var2);
sub doMyFunc {
...
}
now my question is how to properly implement the part of the code where perl should determine the "idle state" of Win32, in which the user neither presses anything nor moves the mouse ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.