a Label's destination dynamic name possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

a Label's destination dynamic name possible?

03 May 2024, 13:27

hello i am trying to make a gosub or hotkey destination dynamic but it has to work like my example where i have the part that i need to be dynamic in between %% because this destination is inside my mastermacro and skips all the button related stuff and enables putting whatever macro was made under a button to be used as a hotkey so its important it knows at what number it is because to acces the macro with a hotkey i have to type Button1 in hotkey options in this example

the macro itself starts up much higher with a label called mastermacro the button nr label is there only for my turn a button into a hotkey option, on a button click my tool writes its button nr to ini first so that inside my mastermacro and all setup gui's the correct information is loaded and also open for editing just that buttons settings. all setup gui's load this value to display the right information (my tool has 664 programmable buttons)

if i can solve this i can make my macro dynamic for the most part and use a gosub for the biggest part and shave of a pile of code. i created a simple example of my needs but in my main script it would come from ini

Code: Select all

#SingleInstance, Force

Temp=1
return

Button%Temp%:
  Tooltip, i work
  sleep, 1000
  tooltip
return

^W::      ; for testing
GoSub, Button1
return
i get the error : ==> Target label does not exist. so is this not possible?
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: a Label's destination dynamic name possible?

03 May 2024, 13:43

Hello,

See documentation about labels. You can achieve your goal with other approaches.

Code: Select all

#Requires AutoHotkey v1.1.33.11
temp := 1

^w::GoSub % "Button" temp

Button1:
ToolTip % A_ThisLabel
Sleep 1000
ToolTip
Return
Alternatives include #If contexts and the :arrow: Hotkey command.
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: a Label's destination dynamic name possible?

03 May 2024, 13:47

mikeyww wrote:
03 May 2024, 13:43
Hello,

See documentation about labels. You can achieve your goal with other approaches.

Code: Select all

#Requires AutoHotkey v1.1.33.11
temp := 1

^w::GoSub % "Button" temp

Button1:
ToolTip % A_ThisLabel
Sleep 1000
ToolTip
Return
in the context of my tool that is not gonna work, but that does anwser my question thank you mikey i stick to a macro for every button
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: a Label's destination dynamic name possible?

03 May 2024, 13:51

You do not need one. An example is below.

Code: Select all

#Requires AutoHotkey v1.1.33.11
temp := 5

^w::GoSub % "Button" temp

Button1:
Button2:
Button3:
Button4:
Button5:
Button6:
ToolTip % A_ThisLabel
Sleep 1000
ToolTip
Return
You do not even need all of these labels. You can have a single label and just act according to your variable.

Code: Select all

#Requires AutoHotkey v1.1.33.11
temp := 5

^w::GoSub Button

Button:
ToolTip % temp
Sleep 1000
ToolTip
Return
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: a Label's destination dynamic name possible?

03 May 2024, 14:05

i know but i show you the context and why that wont work for me
this is purely to demonstrate what i am tring to achieve not my actual macro (line 14)

Code: Select all

Macro264:
	IniWrite,264,settings\ButtonClickedNR.ini,setupinfo,NR
	IniWrite,5,settings\GuiInUseNR.ini,setupinfo,NR
	GoSub, MasterMacro
	return	
	
MasterMacro:	
	IniRead,CurrentButtonNR,settings\ButtonClickedNR.ini,setupinfo,NR
	KeyDown:=A_TickCount
	Keywait, LButton
	Duration:=(A_TickCount-KeyDown)
If  (Duration<OpenOnWindow1)
	{
		Button264: ; this is how i use it, from here this can be an hotkey 
		tempwindow := % IfWinExist[CurrentButtonNR]
		IfWinExist, % IfWinExist[CurrentButtonNR]
		{
			WinActivate, % WinActivate[CurrentButtonNR]
			;all my macro code here
			return
		}
		return
	}
	else If (Duration>OpenOnWindow1) and If (Duration<OpenOnWindow2)
			{ 	
                                 ; code here
				return
			}
	else If (Duration>OpenOnWindow2) and If (Duration<OpenOnWindow3)
			{   
                                ; code here
				return
			}
	else If (Duration>OpenOnWindow3)
			{   
                                 ; code here
				return
			}
	else Abort()
return
updated it a bit and removed a few elements that could confuse, note that currently i have all this as one macro and currentbuttonnr is just a number and not the word
Last edited by peter_ahk on 03 May 2024, 14:17, edited 1 time in total.
User avatar
mikeyww
Posts: 28869
Joined: 09 Sep 2014, 18:38

Re: a Label's destination dynamic name possible?

03 May 2024, 14:16

Although you have provided no description of what should happen, and no example, I see no problems or barriers.

Code: Select all

#Requires AutoHotkey v1.1.33.11
duration        := 5
CurrentButtonNR := 2

#If (duration > 3)
^w::
Button:
If CurrentButtonNR
     MsgBox % CurrentButtonNR
Else MsgBox xxxxxxxxxxx
Return
#If
peter_ahk
Posts: 168
Joined: 13 Feb 2024, 14:49

Re: a Label's destination dynamic name possible?

03 May 2024, 14:27

that would disable my ability to to turn a macro into a hotkey coz i have a setup gui that allows setting up hotkeys and to access macro 2 i need to type Button2 as that would the the label inside my macro just past the button stuff. anyway never mind mikey i stick to my 1 macro per button everytime i try to change it i loose weeks in time its just not worth it to me anymore i trow in the towl coz its eather beyound me or just wont work eather way my pile of code does work and what do i have to gain here realy only a few mb of used memory

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 146 guests