Author
Topic: Inactivity (Read 6859 times)

I am configuring a computer for a public library. I would like to have a script that detects when there is no activity (keystrokes or mouse) and if a certain amount of time has passed I would like the script to restart the browser (Chrome). Is this possible?

TimeDelay(5);this is testing. I have to click on the application in these 5 seconds

currentwin = WinGetactive( )

; just to see what it thinks is the current windowMessage("WinGetActive", "Current window is %currentwin%.")

WinClose("currentwin")TimeDelay(5)Run("incognito","")

The error is that it can't find the window in this line WinClose("currentwin")

I have also tried ("~currentwin") (~new tab") (which is the beginning of the window name.

Can you help?

thanks.

Quotation marks are used to specify a string. Yet, it looks like you are trying to pass the variable currentwin to the WinClose function. You will need to remove the quotation marks around your variable name to have it treated as a variable rather than a string.

Code: Winbatch

TimeDelay(5);this is testing. I have to click on the application in these 5 seconds

currentwin =WinGetActive()

; just to see what it thinks is the current windowMessage("WinGetActive", "Current window is ":currentwin:".");Uses the colon operator for string concatenation.

Thanks for your help. I don't know if this is possible, but it really does check for inactivity every so many seconds and restarts Chrome. Is there any way to have it not do it if no one has used the computer in between? For example, I am sitting next to my test computer doing other things and it keeps closing Chrome and then opening it. It would only need to do that if I done something on that computer and THEN was inactive.

Thanks for your help. I don't know if this is possible, but it really does check for inactivity every so many seconds and restarts Chrome. Is there any way to have it not do it if no one has used the computer in between? For example, I am sitting next to my test computer doing other things and it keeps closing Chrome and then opening it. It would only need to do that if I done something on that computer and THEN was inactive.

; If we have a value from the function ret = DllCall(DirWindows(1):'user32.dll',long:'GetLastInputInfo',lpbinary:LastInputInfo) If ret ; Get the number of ticks at the point when the last activity was seen LastInputTicks = BinaryPeek4(LastInputInfo,4) ;dwTime

; Number of idle ticks = system uptime ticks - number of ticks at last input IdleTicks = systemUptime - LastInputTicks EndIf

Here is my undebugged attempt at improving that code to fit your needs:

Code: Winbatch

#DefineFunction GetLastInput(); Note: The following script is fundamentally flawed because the 'GetTickCount' and possibly the 'GetLastInputInfo 'function will start returning negative numbers ; after the computer has been up for ~24.85 days and 'GetTickCount' will reset after ~49.7 days. This means that you can get either negative or incorrect positive ; idle times if the computer is up long enough.

; Set the struct LastInputInfo =BinaryAlloc(8)BinaryPoke4(LastInputInfo,0,8);cbSizeBinaryPoke4(LastInputInfo,4,0);dwTime

; If we have a value from the function ret =DllCall(DirWindows(1):'user32.dll',long:'GetLastInputInfo',lpbinary:LastInputInfo)If ret; Get the number of ticks at the point when the last activity was seen LastInputTicks =BinaryPeek4(LastInputInfo,4);dwTimeEndIf

LastInputInfo =BinaryFree(LastInputInfo)

Return LastInputTicks#EndFunction

secondstowait =90BoxOpen('Number of seconds since last input','')While@true

lastinput =Int((GetTickCount()- GetLastInput())/1000)BoxText(lastinput)If lastinput > secondstowait ;check if it has been 60 seconds ;Do whatever commands here that you want to happen ;if no user input is detected in last {n} seconds. Pause("Notice","System Idle for ":secondstowait)EndIfEndWhileexit