Problem with break loop by click key Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Problem with break loop by click key

09 Aug 2021, 10:44

Hello, I have got problem with code bellow (RMB Break doesn't work), I want to break the loop in LabelA by clicking RMB key. Any ideas how to do it?

Code: Select all

global klub
global czy:= false
global abc:= 0
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Hotkey, %LabelAKey%, LabelA
Hotkey, %LabelBKey%, LabelB
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
LabelA:
SoundBeep, 300, 100
if(czy=true){
if (true=klub){
abc=2
    loop
    {
        Send {m}
        Send {Down 3}{Enter}{Down 4}{Enter} 
        break
    }   
}
else{
abc=2
    loop
    {
        Send {m}
        Send {Down 2}{Enter}{Down 4}{Enter}
        break   
    }   
}
}
else
MsgBox,, Script, ERROR, first use LabelB
return
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
LabelB:
SoundBeep, 300, 100
czy:=true
MSGBox, 4, Script, Yes/No? 
IfMsgBox Yes
klub := true
else
klub := false
return
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
~RButton::
if(abc=1){
Run script.ahk
eksit()
return
}
else if(abc=2){
Send break
abc=0
return
}
return
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
eksit(){
	ExitApp
}
Last edited by Hajdes on 09 Aug 2021, 11:17, edited 1 time in total.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Problem with break loop by click key

09 Aug 2021, 10:51

I believe that AHK v2 can terminate threads (I am told). In v1.x, some methods are listed below.

1. Add conditional statements to the thread that act according to a variable set by the triggered hotkey.
2. Reload the script.
3. Run the subroutine as a separate script that can be WinClosed.
4. Pause the script (also pauses other threads, and resumes when unpaused).

Additional ideas & examples:

https://www.autohotkey.com/boards/viewtopic.php?p=250076#p250076

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=82813
Hajdes
Posts: 38
Joined: 30 Jul 2021, 17:29

Re: Problem with break loop by click key

09 Aug 2021, 11:15

mikeyww wrote:
09 Aug 2021, 10:51
I believe that AHK v2 can terminate threads (I am told). In v1.x, some methods are listed below.

1. Add conditional statements to the thread that act according to a variable set by the triggered hotkey.
2. Reload the script.
3. Run the subroutine as a separate script that can be WinClosed.
4. Pause the script (also pauses other threads, and resumes when unpaused).

Additional ideas & examples:

https://www.autohotkey.com/boards/viewtopic.php?p=250076#p250076

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=82813
1. I can't reload the script because after reload

Code: Select all

global czy:= false
So when it is false it show this msg box

Code: Select all

MsgBox,, Script, ERROR, first use LabelB
and after reload I must always use LabelB

Code: Select all

LabelB:
SoundBeep, 300, 100
czy:=true
MSGBox, 4, Script, Yes/No? 
IfMsgBox Yes
klub := true
else
klub := false
return
which is why I used loop but it doesn't want to work how I want

2. AHK v2 not work for me
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Problem with break loop by click key  Topic is solved

09 Aug 2021, 11:20

If you need to abort the whole script by reloading it, but you want to start the script differently, you could IniWrite guiding information, and then IniRead it back upon running the script again.

Another approach could be to run the script with a command-line argument that tells the script what to do.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 342 guests