Page 1 of 1

Script for holding LButton and Releasing it upon pressing LButton

Posted: 22 Jul 2020, 08:57
by curiousguy
Hi all,
I'm trying to have my script send Left Mouse Button and hold it for a few minutes, and only release on actual clicking of the left mouse button, and then stay in "standby mode".
The script does release the left mouse button upon clicking, but the script wouldn't work second time I'm pressing F11... My guess is that the reason it doesn't work the second time is because the script is either still running (incorrectly) or is incorrectly terminated.

Code: Select all

#SingleInstance, force
#NoTrayIcon
#Persistent


Loop 
{
F11::
Send {lbutton down}
Sleep, 1200000 ; 120 seconds pause

KeyWait, LButton
Send {lbutton up}
return
}
Would appreciate any input!

Re: Script for holding LButton and Releasing it upon pressing LButton

Posted: 22 Jul 2020, 09:24
by Rohwedder
Hallo,
your pause is 1200 seconds!
your loop stops immediately:
https://www.autohotkey.com/docs/Scripts.htm#auto
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first).
Try this.

Code: Select all

#SingleInstance, force
#NoTrayIcon
#Persistent

Loop ;your loop stops with [c]F11::[/c]
{
F11::
Send {lbutton down}
Sleep, 1200 ; 1.2 seconds pause
SoundBeep, 5000 ;Bib
KeyWait, LButton
SoundBeep, 500 ;Bob
Send {lbutton up}
return
}

Re: Script for holding LButton and Releasing it upon pressing LButton

Posted: 22 Jul 2020, 10:23
by curiousguy
@Rohwedder
thank you for your input and explanation! Your script (a modified version, that is) fails the same as did mine, though :/ I.e. after releasing the "LButton down" with left mouse click, the script won't respond to further f11 presses.
And yeah, I do need 120 seconds lbutton down, but very likely will have to release the left mouse button earlier, i.e. 20:00:00 pm deployment, 20:00:45 left mouse clicking, 20:00:59 second deployment of script.

Code: Select all

#SingleInstance, force
#NoTrayIcon
#Persistent

Loop ;your loop stops with [c]F11::[/c]
{
F11::
Send {lbutton down}
Sleep, 120000
KeyWait, LButton
Send {lbutton up}
return
}

Re: Script for holding LButton and Releasing it upon pressing LButton

Posted: 23 Jul 2020, 06:04
by curiousguy
@Rohwedder Any idea why the script wouldn't respond to F11 presses after I've released the left moust button by clicking left mouse button?

Re: Script for holding LButton and Releasing it upon pressing LButton

Posted: 23 Jul 2020, 10:55
by Rohwedder
Here the script reacts to F11 after I released the left mouse button (audible on my "Bop") but of course only after the sleep was finished.