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

'Lo,

I have a very simple question, I think, but an answer is hard to find: I've read the ActivePerl (5.6.1) documentation about the Win32::and Win32Api:: modules, I've tried Google and I've tried the PM Super Search.

The question is just this: how do I track the idle time of the current user on my Windows 98 computer?

Update: I've also checked Categorized Q&A and the Code Catacombs.
Update 2:Checked CPAN too.
  • Comment on Windows 98: track the current user's idle time

Replies are listed 'Best First'.
Re: Windows 98: track the current user's idle time
by Grygonos (Chaplain) on Mar 23, 2004 at 21:41 UTC
    Are you absolutely sure it's stored somewhere in the system? the system may keep track of it internally and not publish it to outside eyes. I haven't looked at it but it's just something to consider. Turns out (according to this site) that you can't get ahold of it easily... but using Win32::API you can "roll-your-own" as they put it here.

    Grygonos
      I've found that article too. Unfortunately, it doesn't state which DLL to import from :(
        ??? He provides the dll (sourcecode and all) you just have to download it
Re: Windows 98: track the current user's idle time
by flyingmoose (Priest) on Mar 23, 2004 at 21:48 UTC
    You may want to check MSDN but I recommend searching it using Google and using the "site:msdn.microsoft.com" as a search term since MSDN is a beast to navigate. It's a great resource for that hard-to-find obfuscated Microsoft documentation though.

    See what comes up

    Once you find something that works, I think you will be able to load and execute the functions using Win32::API. Note that I've never called new functions never-before-made-to-Perl using Win32::API, but it appears to work from examples other monks have used. I do a lot of Win32 coding for work in C++, just not in Perl (dang it).

    update: The link posted at top shows what you need to do.

Re: Windows 98: track the current user's idle time
by BrowserUk (Patriarch) on Mar 23, 2004 at 21:48 UTC

    Would you care to explain what you mean by "the idle time of the current user"?

    Thinks: "Hey! Just cos I wasn't typing doesn't mean I was idle." :)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
      Yes, I will :)

      It's to shut down that shitting MSN Messenger. My sister sometimes just doesn't quit it, and then, when I take place here, MSN is still loaded and then I've to close it myself. I just want it to be closed when she leaves the computer.

        You could look at using Win32::API to monitor the activation of the screen saver using SystemParametersInfo with with an action of SPI_GETSCREENSAVERRUNNING to determine when the screensaver kicks in (assuming it is enabled) and use that as your que for doing whatever your going to do.

        You'd probably want to use something like Win32::Daemon or Win32::Daemon::Simple to put your script in the background, though it is probably easier to just right-click and exit:)


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
Re: Windows 98: track the current user's idle time
by muba (Priest) on Mar 23, 2004 at 22:11 UTC
    Well... I've been searching a lot now, using and modifying the search terms offered. I've read complete threads on forums, many MSDN articles but I just don't see what I should do. The one article on Code Project doesn't tell which DLL to import from.
    Don't get me wrong, I of course appreciate your help. The only thing is... it doesn't help :)
    Any more suggestions, or should I just give up? (Long time ago I did that :D)
      Reading that again, it does look messy. There are a lot of functions to import and some structures are involved as well! Ugh! It first looked like you want SetWindowsHookEx in User32.lib according to the bottom of the MSDN page if you were going by the CodeProject article. MSDN usually lists header files and libraries at the bottom of these pages, along with the applicable versions of Windows.

      I will say, from reading the article again, this is implementing a timer and using some callbacks, which is going to get really ugly FAST. I'm sorry, but my help now isn't helping any more either.

      Did I tell you how much I hated Microsoft API's?

      We know this is possible (at least using undocumented API's) since Windows screensavers do this. Can I ask why you are trying to get this info? It might be possible to do something sneaky like (DARE I SAY IT?) find some Windows screensaver source on the internet, and install your program as a screensaver (using pure C++ code) embedding a Perl interpreter when neccessary? Do you enjoy pain?

      The last bit of brainstorming I have is to just check the mouse position and snoop on the keyboard, but I have no idea exactly how that is possible either without a huge performance drain. It _really_ sounds like you want to register for callbacks or to find a way to query this info -- but where?

        We know this is possible (at least using undocumented API's) since Windows screensavers do this.
        No they don't. Screensavers are launched by the system. So it's the system that keeps track of user activity.

        And they just check their Windows messages, just like any normal Windows app, to detect if there's any mouse or keyboard activity, to know when to exit.