problem with script

Get help with using AutoHotkey and its commands and hotkeys
YossiN
Posts: 7
Joined: 07 Oct 2020, 10:58

problem with script

Post by YossiN » 20 Jan 2021, 04:57

I have the following script that if I'm not doing anything for some time it to co switch use in windows 10:
===================================

Code: Select all

 CheckInactivity:
 SetTimer, CheckInactivity, 60000 ; Check every minute

 If(A_TimeIdlePhysical > 900000) ; If the user has been idle for more than 15	 minutes
 {
	run c:\users\yossi\documents\zmani\tsdiscon
 }
 return
[Mod edit: [code][/code] tags added.]
===================================

lately I have a problem that it jups to switch user at short intervals and don't wait the 15 minutes
is something wrong with the script?
maybe I should change the "tsdiscon" to other (maybe internal) command?

other ideas?

thanks
Last edited by gregster on 20 Jan 2021, 10:21, edited 1 time in total.
Reason: Topic moved to 'Ask For Help'.

garry
Posts: 2630
Joined: 22 Dec 2013, 12:50

Re: problem with script

Post by garry » 20 Jan 2021, 08:59

EDIT : modified A_TimeIdlePhysical > A_TimeIdle

-if you do nothing in 5 seconds it opens once a folder
-if you close the folder it opens again in 5 seconds if you do nothing

Code: Select all

;- problem with script 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=85866

;- EDIT : modified A_TimeIdlePhysical > A_TimeIdle

;example : 
-if you do nothing in 5 seconds it opens once a folder
-if you close the folder it opens again in 5 seconds if you do nothing
;--------------------------------------------------------------------
#warn
#noenv
#persistent
setworkingdir,%a_scriptdir%
settitlematchmode,2
myfolder=C:\TEST\TESTSUB1
SplitPath,myfolder, name, dir, ext, name_no_ext, drive
SetTimer, CheckInactivity,1000  ;- check every second
return
;----------------
CheckInactivity:
If(A_TimeIdle >5000 )   ;- If the user has been idle for more than 5 seconds
 {
 try
   {
   run,%myfolder%
   SetTimer, CheckInactivity,off
   settimer,aas,1000
   }
 catch e 
   {
   xxx:=e.Message
   msgbox, 262208,ERROR,Error=`n%xxx%`nFOLDER '%myfolder%' NOT exists .
   exitapp
   }
 }
return
;----------------
aas:
If (WinID := WinExist("A"))  			;- active window
 {
 WinGetTitle, Title, ahk_id %WinID%		;- title of a window or active browser card
 if title contains %name%
   return
 else
   {
   settimer,aas,off
   SetTimer, CheckInactivity,on
   }
 }
return
;----------------
esc::exitapp                           ;- quit this script
;==========================
Example-2 : start a program

-if you do nothing in 5 seconds it starts charmap
-if you close charmap it starts again in 5 seconds if you do nothing

Code: Select all

#persistent
SetTimer, CheckInactivity,1000  ;- check every second
return

CheckInactivity:
If(A_TimeIdle >10000 ) ; If the user has been idle for more than 5 seconds
 {
 run,charmap
 SetTimer, CheckInactivity,off
 settimer,aas,1000
 }
return

aas:
Process, Exist, charmap.exe
If ErrorLevel=0   ;- if process not exist
  {
  settimer,aas,off
  SetTimer, CheckInactivity,on
  }
;If ErrorLevel
;  process,close,charmap.exe
return

esc::exitapp
Last edited by garry on 20 Jan 2021, 13:30, edited 1 time in total.

YossiN
Posts: 7
Joined: 07 Oct 2020, 10:58

Re: problem with script

Post by YossiN » 20 Jan 2021, 12:54

sorry, I don't understand
can you explain IN SIMPLE WORDS? :-)
thanks

garry
Posts: 2630
Joined: 22 Dec 2013, 12:50

Re: problem with script

Post by garry » 20 Jan 2021, 13:36

I had a failure with A_TimeIdlePhysical , I used it the first time
I don't know what you want to do , ask again


Example-1
-if you do nothing in 5 seconds it opens once a folder
-if you close the folder , it opens again in 5 seconds if you do nothing

the second example is same , instead a folder it starts a program

Example-2 : start a program

-if you do nothing in 5 seconds it starts charmap
-if you close charmap , it starts again in 5 seconds if you do nothing

Post Reply

Return to “Ask For Help”