viewpoint-particle

Author Topic: Inactivity  (Read 5487 times)

jfrasier

  • Newbie
  • *
  • Posts: 23
Inactivity
« on: August 14, 2013, 10:11:32 am »
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?

Thanks

Jane

Deana

  • Wilson WindowWare Tech Support
  • Tech Support
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Inactivity
« Reply #1 on: August 14, 2013, 10:28:32 am »
You are in luck. There is a code sample containing a UserDefinedFunction called Idle_Tick to handle this in the tech database: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/DllCall~Information+Check~for~Input~Idle~-~No~User~Input.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #2 on: August 14, 2013, 11:34:17 am »
Thanks. I was trying to figure out something along those lines but was stuck.

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #3 on: August 14, 2013, 01:38:05 pm »
I am kind of breaking this down into smaller pieces to test.

I have :

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 window
Message("WinGetActive", "Current window is %currentwin%.")

WinClose("currentwin")
TimeDelay(5)
Run(currentwin, "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.

Deana

  • Wilson WindowWare Tech Support
  • Tech Support
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Inactivity
« Reply #4 on: August 14, 2013, 02:00:33 pm »
I am kind of breaking this down into smaller pieces to test.

I have :

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 window
Message("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 window
Message("WinGetActive", "Current window is ":currentwin:".") ;Uses the colon operator for string concatenation.

WinClose(currentwin)
TimeDelay(5)
Run("incognito","")
.
Deana F.
Technical Support
Wilson WindowWare Inc.

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #5 on: August 19, 2013, 01:57:16 pm »
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 again.

Jane

Deana

  • Wilson WindowWare Tech Support
  • Tech Support
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Inactivity
« Reply #6 on: August 19, 2013, 02:42:37 pm »
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 again.

Jane

Please post the code you are using.
Deana F.
Technical Support
Wilson WindowWare Inc.

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #7 on: August 20, 2013, 07:44:15 am »
#DefineFunction Idle_Tick()
   ; Get the system uptime
   systemUptime = GetTickCount()

   ; The tick at which the last input was recorded
   LastInputTicks = 0

   ; The number of ticks that passed since last input
   IdleTicks = 0

   ; Set the struct
   LastInputInfo = BinaryAlloc(8)
   BinaryPoke4(LastInputInfo,0,8);cbSize
   BinaryPoke4(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) ;dwTime

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

   LastInputInfo = BinaryFree(LastInputInfo)

   ;Convert milliseconds to seconds
   SystemUptime = systemUptime / 1000
   IdleTime = IdleTicks / 1000
   LastInput = LastInputTicks / 1000
   Return IdleTime
#EndFunction


While @TRUE
   tick = Idle_Tick()
   If tick==20
      currentwin = WinGetActive()
      WinClose(currentwin)
      TimeDelay(5)
      Run("Chrome","-incognito")
      TimeDelay(1)

   EndIf


EndWhile

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #8 on: December 19, 2013, 02:22:16 pm »
I am still interested in finding an answer to my question above. Thanks.

Jane

Deana

  • Wilson WindowWare Tech Support
  • Tech Support
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Inactivity
« Reply #9 on: December 20, 2013, 08:53:02 am »
I suppose you will need to keep track of the last input time. IF you look closely at the UDF it calculates three possible values but only returns one (IdleTime):

Code: Winbatch
;Convert milliseconds to seconds
SystemUptime = systemUptime / 1000
IdleTime = IdleTicks / 1000
LastInput = LastInputTicks / 1000
Return IdleTime

Maybe modify the UDF to return both IdleTime and Lastinput as a tab delimited list.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

  • Tech Support
  • *****
  • Posts: 2088
    • WinBatch
Re: Inactivity
« Reply #10 on: December 20, 2013, 12:53:22 pm »
The script has several issues, not the least of which is the line "If tick==20".
"le succès est une terrible maîtresse"
(French translation), Bill Gates


Deana

  • Wilson WindowWare Tech Support
  • Tech Support
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: Inactivity
« Reply #11 on: December 20, 2013, 01:13:51 pm »
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);cbSize
   BinaryPoke4(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) ;dwTime
   EndIf

   LastInputInfo = BinaryFree(LastInputInfo)

   Return LastInputTicks
#EndFunction

secondstowait = 90
BoxOpen('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)
   EndIf
EndWhile
exit
Deana F.
Technical Support
Wilson WindowWare Inc.

jfrasier

  • Newbie
  • *
  • Posts: 23
Re: Inactivity
« Reply #12 on: December 20, 2013, 03:02:13 pm »
Thank you so much for taking the time to do this. I am trying to make it work for my situation and am not quite there. i will continue to work on it next week. Right now it is kinda sorta working.

Jane