Stop a loop with A_TimeIdlePhysical

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Melancoholic
Posts: 2
Joined: 17 May 2018, 14:57

Stop a loop with A_TimeIdlePhysical

17 May 2018, 15:22

Hello guys!
I want to script a loop which starts with user input and ends with a keystroke/moving the mouse.
Looking at other posts I found "A_TimeIdlePhysical" which could help but in every instance I saw the code it was always used to start something not to end it.
And the line I was using to break the loop didn't seemed to work
The code I'm using is
Spoiler
Can anybody help me?
I'm also fine to end the loop with a specific keystroke like ctrl+l.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Stop a loop with A_TimeIdlePhysical

17 May 2018, 15:39

dont use deprecated commands(IfLess, etc) in new scripts

Code: Select all

Esc::ExitApp
^k::
{
	Loop
	{
		Send your_text_here{Enter}
		Sleep rand(1000, 2000)

		if (A_TimeIdlePhysical < 100)
			break
	}
return
}

rand(a, b) {
	Random, rand, a, b
	return rand
}

Melancoholic
Posts: 2
Joined: 17 May 2018, 14:57

Re: Stop a loop with A_TimeIdlePhysical

17 May 2018, 16:04

swagfag wrote:dont use deprecated commands(IfLess, etc) in new scripts

Code: Select all

Esc::ExitApp
^k::
{
	Loop
	{
		Send your_text_here{Enter}
		Sleep rand(1000, 2000)

		if (A_TimeIdlePhysical < 100)
			break
	}
return
}

rand(a, b) {
	Random, rand, a, b
	return rand
}

Thank you, but pressing a key or moving a mouse didn't break the loop
However Esc::ExitApp did.
FYI I started using AHK today
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Stop a loop with A_TimeIdlePhysical

17 May 2018, 16:54

yeah, i noticed now too that theres the issue that when the script is sleeping, naturally, no checks are being done, so moving the mouse or pressing a key wont break it
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Stop a loop with A_TimeIdlePhysical

17 May 2018, 20:48

Code: Select all

#NoEnv

Esc::ExitApp

^k::
    KeyWait, Ctrl
    KeyWait, k
	Loop
	{
		Send your_text_here{Enter}
        if (randSleep(1000, 2000) = false)
            break
	}
return

randSleep(a, b) {
	Random, r, a, b
    Loop, 50
    {
        Sleep r//50
        if (A_TimeIdlePhysical < 25)
            return 0
    }
	return 1
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, captainsmackyou, mikeyww, sofista and 67 guests