jpindar Posted September 27, 2007 Share Posted September 27, 2007 I'm trying to write a script that will close a certain program if the user has had it running, but hasn't used it for some time. I could write it so it will close the program if it's been minimized or otherwise not 'active' (having focus) for a time, but that won't get the case when they leave the program 'active' when they walk away from their computer. Is there anyway to tell if a window has gotten any mouse clicks or keypresses recently? Thanks. Link to comment Share on other sites More sharing options...
sandin Posted September 27, 2007 Share Posted September 27, 2007 (edited) will this help you: Opt("WinTitleMatchMode", 2) $time = 5000 ;5 sec $timer = TimerInit() $title = "Notepad" run("notepad") AdlibEnable("AdlibFunc", 10) func AdlibFunc () if Not WinActive($title) then if TimerDiff($timer)>$time Then WinClose($title) Exit EndIf Else $timer = TimerInit() EndIf EndFunc While 1 Sleep(10) WEnd ? Edited September 27, 2007 by sandin Some cool glass and image menu | WinLIRC remote controler | Happy Holidays to all... | Bounce the sun, a game in which you must save the sun from falling by bouncing it back into the sky | Hook Leadtek WinFast TV Card Remote Control Msges | GDI+ sliding toolbar | MIDI Keyboard (early alpha stage, with lots of bugs to fix) | Alt+Tab replacement | CPU Benchmark with pretty GUI | Ini Editor - Edit/Create your ini files with great ease | Window Manager (take total control of your windows) Pretty GUI! | Pop-Up window from a button | Box slider for toolbar | Display sound volume on desktop | Switch hotkeys with mouse scroll Link to comment Share on other sites More sharing options...
jpindar Posted September 27, 2007 Author Share Posted September 27, 2007 You're missing my point. WinActive will only tell you if the window is "active", that is, if it is on top and has focus. If the person is using a program, then gets up and goes home without closing or minimizing it, it will stay "active" all night. I need to know if the person has done anything such as clicked the mouse on or typed something into that program. Link to comment Share on other sites More sharing options...
jpindar Posted September 27, 2007 Author Share Posted September 27, 2007 I suppose I could pop up a messagebox or otherwise steal focus from the program every once in a while, and see it they take it back, but that'd annoy them if they are actively using their program. Of course, it'd hardly be the only program that annoys users by (apparently) randomly stealing their focus... Link to comment Share on other sites More sharing options...
Tasmania Posted September 27, 2007 Share Posted September 27, 2007 will this help you: Opt("WinTitleMatchMode", 2) $time = 5000 ;5 sec $timer = TimerInit() $title = "Notepad" run("notepad") AdlibEnable("AdlibFunc", 10) func AdlibFunc () if Not WinActive($title) then if TimerDiff($timer)>$time Then WinClose($title) Exit EndIf Else $timer = TimerInit() EndIf EndFunc While 1 Sleep(10) WEndoÝ÷ Ûú®¢×ªº^©oÝ÷ ÚÚºÚ"µÍYÝÚ[XÝ]J ÌÍÝ]JHÜÚ[XÝ]J ÌÍÝ]JH[ ? That's my random stab at it... I'm not sure what that will do, but hey! Link to comment Share on other sites More sharing options...
BobK Posted September 27, 2007 Share Posted September 27, 2007 You can use WinGetText and ControlCommand periodically to examine certain controls in the program to see if there has been any change, such as entering or deleting text in an Edit, change of caret position, or change of selection in a Listbox. Can you tell us a little more about the program you wish to monitor? Link to comment Share on other sites More sharing options...
JustinReno Posted September 27, 2007 Share Posted September 27, 2007 Why not just use If Process Exists? Link to comment Share on other sites More sharing options...
strate Posted September 28, 2007 Share Posted September 28, 2007 Is the program "OnEvent"? INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station... Link to comment Share on other sites More sharing options...
ChrisL Posted September 28, 2007 Share Posted September 28, 2007 See if the winactive() then see if the mouse moves by checking MouseGetPos() and see if it matches the same as last time remember to check MouseGetPos[0] and MouseGetPos[1] then you could also Keep running through _ispressed() to see if any key has been pressed, you'd have to generate a list of all the keys to check and it will probably take up a bit of CPU. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
Siao Posted September 28, 2007 Share Posted September 28, 2007 (edited) Try this: expandcollapse popupGlobal $nInactiveTimer = 0, $nLastInput = 0 ;idling timers Global $nIdlingAllowed = 5000 ;how much time allow idling (miliseconds) Global $nCheckFrequency = 1000 ;how often check (miliseconds) ;~ ;target app. Run("notepad") WinWait("Untitled - Notepad") $hWin = WinGetHandle("Untitled - Notepad") ;stuct to receive GetLastInputInfo() data. Global $tagLASTINPUTINFO = DllStructCreate("uint; dword") DllStructSetData($tagLASTINPUTINFO, 1, 8) Global $pLASTINPUTINFO = DllStructGetPtr($tagLASTINPUTINFO) ;main loop While 1 Sleep($nCheckFrequency) If WinActive($hWin) Then $nInactiveTimer = 0 $nLastInput = _GetLastInput() Else $nInactiveTimer += $nCheckFrequency EndIf If $nInactiveTimer > $nIdlingAllowed Or $nLastInput > $nIdlingAllowed Then MsgBox(0,'FYI', 'Target app has been unused for more than ' & $nIdlingAllowed/1000 & ' seconds.') $nInactiveTimer = 0 $nLastInput = 0 EndIf WEnd ; _GetLastInput() ; returns time of user inactivity in miliseconds Func _GetLastInput() If (IsDeclared('pLASTINPUTINFO') <> 1) Or (IsDeclared('tagLASTINPUTINFO') <> 1) Then Return -1 $aRet = DllCall('user32.dll', 'int', 'GetLastInputInfo', 'ptr', $pLASTINPUTINFO) If $aRet[0] = 0 Then Return -1 $aTick = DllCall('kernel32.dll', 'dword', 'GetTickCount') Return $aTick[0] - DllStructGetData($tagLASTINPUTINFO, 2) EndFunc Edited September 28, 2007 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
jpindar Posted September 28, 2007 Author Share Posted September 28, 2007 (edited) Thanks Siao, that seems to work. I've never used these dlls before. Where's a good source of info on them? Edited September 28, 2007 by jpindar Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now