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