Page 1 of 1

right mouse conditional exit or return function within a script

Posted: 24 Feb 2018, 04:06
by Draco
Hi guys, I am in need of help to source code to fit into my AHK script, I have tried and mucked about for hours but am not quite getting the right command,
nor do i posess the knowledge at this point.
What I am trying to achieve is to insert a return/exit command right after my sleep 100 line, that executes the following: After 1 right click (normal not hold)
the right mouse click operates normally but also sends a kill(return or exit) command to the script so it gos back to the start. However if I press and hold the right mouse button in/down
I want the script to execute the remainder of the code till its done. Heres what I have, I assume this will have to be achieved with some sort of conditional/ if statement but I cant seem to crack it.
thats in advance for any assistance. :)

~RButton:: ;"~": When the hotkey fires, its key's native function will not be blocked
sleep 100

while GetKeyState("RButton","P")
{
Send, {\ Down}
Send, [
Sleep 50
}
SEND, {\ Down}{\ Up}{\ Down}{\ Up}
return

Re: right mouse conditional exit or return function within a script

Posted: 25 Feb 2018, 04:54
by Nwb
Does this work?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Rbutton::
now := A_TickCount
While GetKeyState("Rbutton", "P")
	if (A_TickCount-now > 200)
	{
		Send, {\ Down} [
		Sleep 50
		Send, {\ Up} {\ Down} {\ Up}
	}
	else
	{
	    Sleep 300
	    Send, {Rbutton}
	}
return
	
esc:: ExitApp
	

Re: right mouse conditional exit or return function within a script

Posted: 25 Feb 2018, 07:48
by Draco
thanks for trying but the line SEND, {\ Down}{\ Up}{\ Down}{\ Up} in my original code was out side the get keystate for a reason. I didnt want it looped into the right mouse button pressed statement, i had it out side cause i only want to execute that particular line once straight after the getkeystate command and only if the getkeystate command was triggered. if i click right mouse once i dont want anything else to to executed at all. its only if i hold down(ie > 200) do i want the rest to be executed. when i press right click once the script still executes SEND, {\ Down}{\ Up}{\ Down}{\ Up} at the bottom. maybe all i need is to stop that last bit happening and ill be sweet. (that code line still has to occur though if right mouse button is held down, straight after the release of that held down state. Thanks for giving it a crack sorry if i wasnt clear in my code.

Re: right mouse conditional exit or return function within a script

Posted: 25 Feb 2018, 08:05
by Nwb
Oh okay I think I have a grasp on what you want.

Question, why is there no \ up to follow the \ down in the loop?

Re: right mouse conditional exit or return function within a script

Posted: 25 Feb 2018, 08:21
by Nwb
Okay so does this work? I am assuming you forgot the {\ up} to follow the {\ down} after the sleep.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#MaxThreadsPerHotkey 2

Rbutton::
	now:= A_TickCount
	While GetKeyState("Rbutton", "P")
		if (A_TickCount-now > 200)
		{
			Send, {\ Down}{[}
			Sleep, 50
			Send, {\ Up}
		}
Send, {\ Down}{\ Up}{\ Down}{\ Up} 
return

esc:: ExitApp ; exits the script

Re: right mouse conditional exit or return function within a script

Posted: 25 Feb 2018, 18:39
by Draco123
This is so very close to being complete now,(thank you) only thing that needs to change is the line
Send, {\ Down} {\ Up} {\ Down} {\ Up} still occuring on a quick/single right click
this code is still executing with a single right click. this code should only execute after the right mouse button is held down greater then 200. and needs to follow straight after the getkeystate command, but cant be lobbed in with it. So if you can find a way to include that line within the > 200 conditional, whilst be executed straight after the getkeystate command, the script will be complete :).

Re: right mouse conditional exit or return function within a script  Topic is solved

Posted: 26 Feb 2018, 05:24
by Draco
i got it working now thanks for your help.