GrimPimp has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone. This is my first post but won't be my last. Ok now to the meat of it. I want to make a program that determine if a terminal has been idling for a while say 5 minutes then Lock the computer. I have the concept down but i don't know how to detect mouse movement or clicks. I think Term::ReadKey should work for the keyboard detection, but if someone has a better idea im open to change. This will be running in the backround of an XP computer so i can do other things whilst this runs, and it should still detect and stuff. Thanx.

Title edit by tye

Replies are listed 'Best First'.
Re: Idle
by batkins (Chaplain) on Oct 19, 2003 at 18:20 UTC
    Like some of the other posters here, I'm inclined to think that setting a screen saver might be better. Either way, Term::ReadKey will almost certainly not do the job, because it catches keypresses for a terminal window, not for the whole system.

    That said, you might want to check out MSDN and see if there are any functions that will let you determine if the computer is idle. Then use the Win32::API module to call that function and determine when the screen is ready to be locked. Then you can probably call a different function to do the actual locking.


    The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa
Re: Idle
by pg (Canon) on Oct 19, 2003 at 16:59 UTC
    Is it not much easier to just use sceen saver with password protection?
Re: Idle
by jpfarmer (Pilgrim) on Oct 19, 2003 at 17:38 UTC

    I think you'll be working too hard to make this work using Perl. I'd be inclined to either use a Windows screensaver with password protection or look for a freeware program designed to do this. Keeping a shell window open just to keep this Perl program running seems like an inelegant solution.

      Keeping a shell window open just to keep this Perl program running seems like an inelegant solution.
      Nobody is forcing you to have a shell window open ;)(you can do so using wperl, or by running said program as a service -- on win32 of course)

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Idle
by dragonchild (Archbishop) on Oct 19, 2003 at 23:37 UTC
    On a Win32 system, when dealing with a lot of the core stuff, using VBScript sometimes makes more sense. For example, I'll parse XML and make a CSV with Perl, then use VBA to convert that into Word docs. I won't use Perl to make Word docs - VBA is just better for that.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Idle
by Roger (Parson) on Oct 20, 2003 at 07:56 UTC
    I agree that the screen saver with password + 5 minute time-out is the way to go. XP has the built in functionality so why not use it?