Routine executes when i don't want to.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Routine executes when i don't want to.

25 Apr 2023, 10:39

Hello,

So i made a long script which gives the f5 f6 and f7 some routines to do. The syntax i used is :

F5::
{
bla bla
}

F6::
{
bla bla
}
f7::
{
bla bla
}

All the {} are correct, but somehow when i execute F5, the F6 executed too, and when i execute F7, it only works for the first time, after that i have to reload the script and it will work one time again.

I thought i have to add a return before last } of each routine, but that didn't change anything. How should i be doing it so each routine only executes for it's key ?
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Routine executes when i don't want to.

25 Apr 2023, 10:52

The block syntax with { } is used for hotkeys in AHK v2, terminating returns are used in AHK v1. Your description sounds like you might be running AHK v1 - although it wouldn't really explain why returns wouldn't help.
I would recommend to first check your AHK version, then re-check the docs, and then - if you still got problems - I would create a short test script and post it in the appropriate help section (depending on your used AHK version) which would allow helpers to actually reproduce what you are seeing.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: Routine executes when i don't want to.

25 Apr 2023, 11:05

Yes it says file version 1.1.34.3


this test

Code: Select all

F1::
{
run notepad
return
}

F2::
{
run chrome
return
}
[Mod edit: [code][/code] tags added.]

without return executes both rutines, but with return it stoped after first one. Not sure why the script i try to write executes all at once even though i put return :(
Last edited by gregster on 25 Apr 2023, 11:06, edited 1 time in total.
Reason: Moved topic to AHK v1 help.
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Routine executes when i don't want to.

25 Apr 2023, 11:10

DarkSider wrote:
25 Apr 2023, 11:05
Yes it says file version 1.1.34.3
[...]
without return executes both rutines, but with return it stoped after first one.
Yes, this is the expected behaviour in AHK v1. The braces ({ }) won't do anything useful here - and can be removed. Instead a return will terminate a hotkey subroutine. If you leave it out, code execution will fall through into following hotkey subroutines, until a return (implicit or explicit) is encountered.
Not sure why the script i try to write executes all at once even though i put return :(
Can't think of a reason without seeing some code. Perhaps you put it into some context which only gets executes conditionally ? 🤷‍♂️
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: Routine executes when i don't want to.

25 Apr 2023, 11:13

Here it comes, i'm very noob i know it looks terrible :D

Code: Select all


f5::
{
WinGet, var, PID, A
inputbox, wnr, Position in grid, What is the position?,,,,,,,,
winpos = Window%wnr%
;msgbox, %wnr%
;iniwrite, %wnr%, robloxpos.ini, %winpos%, winnumber
iniwrite, %var%, robloxpos.ini, %winpos%, PID
; WINDOW 1
if (wnr = 1)
{
iniwrite, 0, robloxpos.ini, %winpos%, X
}
if (wnr = 1)
{
iniwrite, 0, robloxpos.ini, %winpos%, Y
}

; WINDOW 2
if (wnr = 2)
{
iniwrite, 175, robloxpos.ini, %winpos%, X
}
if (wnr = 2)
{
iniwrite, 0, robloxpos.ini, %winpos%, Y
}


; WINDOW 3
if (wnr = 3)
{
iniwrite, 385, robloxpos.ini, %winpos%, X
}
if (wnr = 3)
{
iniwrite, 0, robloxpos.ini, %winpos%, Y
}

; WINDOW 4
if (wnr = 4)
{
iniwrite, 595, robloxpos.ini, %winpos%, X
}
if (wnr = 4)
{
iniwrite, 0, robloxpos.ini, %winpos%, Y
}

; WINDOW 5
if (wnr = 5)
{
iniwrite, 805, robloxpos.ini, %winpos%, X
}
if (wnr = 5)
{
iniwrite, 0, robloxpos.ini, %winpos%, Y
}

; WINDOW 6
if (wnr = 6)
{
iniwrite, 1015, robloxpos.ini, %winpos%, X
}
if (wnr = 6)
{
iniwrite, 30, robloxpos.ini, %winpos%, Y
}

; WINDOW 7
if (wnr = 7)
{
iniwrite, 1225, robloxpos.ini, %winpos%, X
}
if (wnr = 7)
{
iniwrite, 30, robloxpos.ini, %winpos%, Y
}

; WINDOW 8
if (wnr = 8)
{
iniwrite, 1435, robloxpos.ini, %winpos%, X
}
if (wnr = 8)
{
iniwrite, 30, robloxpos.ini, %winpos%, Y
}

; WINDOW 9
if (wnr = 9)
{
iniwrite, 1645, robloxpos.ini, %winpos%, X
}
if (wnr = 9)
{
iniwrite, 30, robloxpos.ini, %winpos%, Y
}

; WINDOW 10
if (wnr = 10)
{
iniwrite, 0, robloxpos.ini, %winpos%, X
}
if (wnr = 10)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 11
if (wnr = 11)
{
iniwrite, 175, robloxpos.ini, %winpos%, X
}
if (wnr = 11)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 12
if (wnr = 12)
{
iniwrite, 385, robloxpos.ini, %winpos%, X
}
if (wnr = 12)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 13
if (wnr = 13)
{
iniwrite, 595, robloxpos.ini, %winpos%, X
}
if (wnr = 13)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 14
if (wnr = 14)
{
iniwrite, 805, robloxpos.ini, %winpos%, X
}
if (wnr = 14)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 15
if (wnr = 15)
{
iniwrite, 1015, robloxpos.ini, %winpos%, X
}
if (wnr = 15)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 16
if (wnr = 16)
{
iniwrite, 1225, robloxpos.ini, %winpos%, X
}
if (wnr = 16)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 17
if (wnr = 17)
{
iniwrite, 1435, robloxpos.ini, %winpos%, X
}
if (wnr = 17)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 18
if (wnr = 18)
{
iniwrite, 1645, robloxpos.ini, %winpos%, X
}
if (wnr = 18)
{
iniwrite, 265, robloxpos.ini, %winpos%, Y
}

; WINDOW 19
if (wnr = 19)
{
iniwrite, 0, robloxpos.ini, %winpos%, X
}
if (wnr = 19)
{
iniwrite, 500, robloxpos.ini, %winpos%, Y
}

;ultima este prima pe linia 3
return
}

f6::
{
x = 1
loop, 27
{
winn = Window%x%
iniread, outpid, robloxpos.ini, %winn%, PID
iniread, outx, robloxpos.ini, %winn%, X
iniread, outy, robloxpos.ini, %winn%, Y

If (outpid)
{
WinMove, ahk_pid %outpid%,, %outx%, %outy%,
}
outpid:=""
outx:=""
outy:=""
x:= x + 1
sleep, 100
}
return
}

f7::
{
x = 1
loop, 27
{
winn = Window%x%
iniread, outpid, robloxpos.ini, %winn%, PID

If (outpid)
{
WinActivate, ahk_pid %outpid%
WinWait, ahk_pid %outpid%
sendinput, {space}
sendinput, {space}
sendinput, {space}
sleep, 20
}
x:=x+1
}
return
}

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Routine executes when i don't want to.

25 Apr 2023, 11:54

I don't think that I can reproduce your problem with the code you provided - please have another look. Did you close all older instances and reload the script?

Generally, I would recommend to indent it in a way that reflects the structure and the flow of the script and to remove the unnecessary outer braces.
Then gradually simplify it and see if the problem persists.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: Routine executes when i don't want to.

25 Apr 2023, 12:19

Thanks for the help :) Yes i had a look over older instances. I have been using this bracket syntax for years and i usually had similar problem, and had to break routines into one per script, which gets messy if i have 7-8 different scripts running in same time.

Would you recommend moving to v2 ? and you think the script should work without first and last bracket on it ? i tryed on my current version and no luck still.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: Routine executes when i don't want to.

25 Apr 2023, 12:30

Well, i think the problem is in another place this time O.O

So i took just the F7 routing and put it into a single script, closed all other scripts. and the same it executes one time perfectly, then i have to reload the script for it to work.

Code: Select all

f7::
x = 1
loop, 27
{
winn = Window%x%
iniread, outpid, robloxpos.ini, %winn%, PID

If (outpid)
{
WinActivate, ahk_pid %outpid%
WinWait, ahk_pid %outpid%
sendinput, {space}
sendinput, {space}
sendinput, {space}
sleep, 20
}
x:=x+1
}
return

Does the PID temporarily changes ? or what's going on.
DarkSider
Posts: 50
Joined: 29 May 2019, 11:06

Re: Routine executes when i don't want to.

25 Apr 2023, 12:41

Oh i think i know what's happening with this one, i got a msgbox in there, so i have 7 windows open, the 8th call generates outpid = ERROR, then the script "WinWait" for the window to open .. and it freezes there ^^

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rxbie and 277 guests