Settimer Stops Updating Using Gosub

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Roonyroo
Posts: 36
Joined: 29 Jan 2014, 20:29

Settimer Stops Updating Using Gosub

25 Mar 2014, 15:36

Using a gosub causes the settimer to stop updating, no idea why ...

This script works great, detects keys pressed, but the subroutine to detect right mouse movement, disables settimer

Running the script, press any key, the variables in the settimer reset perfectly when a keys detected, but if you use the right mouse button, the rbuttn subroutine disables the settimer, no idea why the timer doesnt resume ...

code :

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.
x:=0

msgbox press a few keys, & then hold down & move around right mouse button, settimer should stop updating

SetTimer, timerx, 50


gosub wx



wx:
{

loop
{

GetKeyState, state, RButton  ; 
if state = D
{
gosub rbuttn
return
}

Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}

{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}

{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
tooltip %x% %SingleKey%
sleep,100
;SetTimer, timerx, 50

if SingleKey!=
{

;sleep 1000
;msgbox  %x% %SingleKey%
x:=0
;gosub wx
}

}
return


timerx:
{
x++

GetKeyState, state, RButton  ; 
if state = D
{
gosub rbuttn
return
}


;tooltip %x% %SingleKey%
}
return
}
return

rbuttn:
{

xsl:=0


loop
{

xsl++

MouseGetPos, xpos, ypos
 
xs%xsl%=%xpos%
ys%xsl%=%ypos%
a:=xs%xsl%
b:=ys%xsl%


tooltip a%a% b%b%

sleep 100

GetKeyState, state, RButton
if state = U
{

tooltip rb up 
;x:=0
;reload
gosub wx
return
}


}
return
}

esc::exitapp
f1::reload





RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: Settimer Stops Updating Using Gosub

29 Mar 2014, 00:49

Settimer will not relaunch a subroutine if its previous occurrence is still running.

Your subroutine never ends, it just gosubs from one label to another. This is because the "rbuttn:" label has a loop which gosubs when the right mouse is released - the return on the line below will never be reached. You have a "gosub wx" which has a loop - if the rbutton is pressed down here, then you do another gosub back to "rbuttn:" creating a never ending circle.....

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Hugh Jars, Mateusz53, peter_ahk, Pianist and 359 guests