Jump to content

Closing Program on user inactivity


Recommended Posts

Dear Community,

I'm quiet new to AutoIt, but starting to loving it. Does anybody know, what is the best way, to close a Program on user inactivity? I looked through several threads.

I think there might be 2 appproaches

1. Use the screensaver to get aware of user inactivity

2. try to monitor mouse movement and use a kind of trigger/timer

so my question is now, does anybody have a few script samples to accomplish that?

would be great to have examples how to gracefully close programs and how to do the monitor inactivity trick.

BTW mostly the Workstations, where the software is running on, are Dual monitor Workstations, is that a problem?

Thank you very much for your help and enjoy your Sunday

regards

Holger

Link to comment
Share on other sites

something like this maybe:?

While 1 ; infinite loop
    
    Sleep(1000) ;1 second sleep

    $ScreenSaverActive = DllCall("user32","int","SystemParametersInfo","int",16,"int",0,"int",0,"int",0)
    $ScreenSaverActive = $ScreenSaverActive[3]
    
    If $ScreenSaverActive = 0 Then
        ConsoleWrite('Screensaver is not active' & @CRLF)
    Else
        ConsoleWrite('Screensaver is active' & @CRLF)   
        Exit
    EndIf   
    
WEnd
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

something like this maybe:?

While 1 ; infinite loop
    
    Sleep(1000) ;1 second sleep

    $ScreenSaverActive = DllCall("user32","int","SystemParametersInfo","int",16,"int",0,"int",0,"int",0)
    $ScreenSaverActive = $ScreenSaverActive[3]
    
    If $ScreenSaverActive = 0 Then
        ConsoleWrite('Screensaver is not active' & @CRLF)
    Else
        ConsoleWrite('Screensaver is active' & @CRLF)   
        Exit
    EndIf   
    
WEnd

Dear Goldenix,

Thank you very much for your reply. This is great, now i have to find a good way, to gracefully close the application.

My last problem is, that sometimes, in case of unsaved changes, there appears an infobox, that asks to save or discard.

For me it is ok to through away (That means discard unsaved changes)

again I thank you very much for your help, I appreciate it.

regards

Holger

Link to comment
Share on other sites

This might lead to wrong choice: there are common situations where the mouse is left alone (long editing session, e.g. programming) and even monitoring keyboard acivity as well could not be right: watching a film or, in a business situation, think of a webcast of videoconference.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

This might lead to wrong choice: there are common situations where the mouse is left alone (long editing session, e.g. programming) and even monitoring keyboard acivity as well could not be right: watching a film or, in a business situation, think of a webcast of videoconference.

Yes, you're right, but this application consumes a license while running. It often happens, that users run away and leave the application open. Unfortunately, the app does not have a timeout itself. So we decided to go the "hard" way.

does anybody have further ideas ....?

regards

Holger

Link to comment
Share on other sites

If the app is mostly keyboard driven (I mean if using the keyboard regularily is almost inevitable) then you could intercept keystrokes and determine if the active window is the expensive app. This could reveal a good criterion to reset a timeout counter.

No wonder those bastard editors don't implement a timeout! How unfair.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

If the app is mostly keyboard driven (I mean if using the keyboard regularily is almost inevitable) then you could intercept keystrokes and determine if the active window is the expensive app. This could reveal a good criterion to reset a timeout counter.

No wonder those bastard editors don't implement a timeout! How unfair.

For me I think the Screensaver approach is a good solution. If the Screensaver is active and then wait i.e. one or two additional minutes would be enough.

I'm now experimenting with the window close command, but this second window (Save unsaved changes) is the hard thing as this window just appears, when there's unsaved work. Unfortunately it has same window title.

regards

Holger

Link to comment
Share on other sites

Try converting this into a Windows handle, as this data is unique at a given time. Then it's much safer know whom you are talking to. Use the search feature, there has numerous examples.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...