check for idle, do action, then wait for another idle

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lancelot
Posts: 10
Joined: 12 May 2021, 11:05

check for idle, do action, then wait for another idle

12 May 2021, 11:15

Quite pleased with this that I've cobbled together in 30 mins from not having dealt with AutoHotKey before. The difficult part was getting x/y coordinates. I kept getting some that worked then they stopped working and when I checked again with window spy the new coordinates for the same location were totally different and then didn't work at all when I tried to use them. Anyway for whatever reason that seems to have fixed itself.

So what I'm trying to achieve is for this script to execute only ONCE per every idle. At the moment it runs every five seconds UNLESS the msgbox is open in which case it doesn't run at all.

I'd like to somehow set a flag so that it doesn't even consider checking for idle again until it's had some stimuli from the user.

many thanks for any help! What a powerful tool.

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
SetTimer, Check, 5000;
return
SetMouseDelay, 10
Check:
If (A_TimeIdlePhysical>=5000)
{
if WinExist("ahk_exe Selling.exe") 
    WinActivate ; 
sleep 2


if !A_IsAdmin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}
MouseClick, left, 1284, 82
sleep 2
MouseClick, left, 700,177
MsgBox You have been auto-logged out.

}
return
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: check for idle, do action, then wait for another idle

12 May 2021, 11:41

After your idle check triggers, you can turn off the timer, and run a different one that checks for the activity that you are seeking. After that, you can reset the conditions and start the first timer again.

Alternative: this might also work if you simply change your idling variable to A_TimeIdle.
Physical input from the user as well as artificial input generated by any program or script (such as the Send or MouseMove commands) will reset this value back to zero.
lancelot
Posts: 10
Joined: 12 May 2021, 11:05

Re: check for idle, do action, then wait for another idle

12 May 2021, 11:44

Thank you - yes - it's exactly that that I know I need to do, but is that something I'd do with a flag like this?

Code: Select all

{
	if (idlecheck<= 0){
	idlecheck:=1
	Sleep 1000
	}
	else if (idlecheck>= 1){
	idlecheck:=0
	Sleep 1000
	}
}
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: check for idle, do action, then wait for another idle

12 May 2021, 12:01

Try: change A_TimeIdlePhysical to A_TimeIdle. Retest.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, Descolada, Oblomov228 and 178 guests