Script for holding LButton and Releasing it upon pressing LButton

Ask gaming related questions
curiousguy
Posts: 5
Joined: 22 Jul 2020, 08:07

Script for holding LButton and Releasing it upon pressing LButton

22 Jul 2020, 08:57

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!
Rohwedder
Posts: 3524
Joined: 04 Jun 2014, 08:33
Location: Germany

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

22 Jul 2020, 09:24

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
}
curiousguy
Posts: 5
Joined: 22 Jul 2020, 08:07

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

22 Jul 2020, 10:23

@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
}
curiousguy
Posts: 5
Joined: 22 Jul 2020, 08:07

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

23 Jul 2020, 06:04

@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?
Rohwedder
Posts: 3524
Joined: 04 Jun 2014, 08:33
Location: Germany

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

23 Jul 2020, 10:55

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.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 6 guests