Can I use variables as normal labels or hotkey labels? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
fx_spencer
Posts: 6
Joined: 06 Dec 2021, 07:45
Contact:

Can I use variables as normal labels or hotkey labels?

Post by fx_spencer » 06 Dec 2021, 08:00

Hello!
I am going to be direct.
As all of you guys know, there are two ways to set a hotkey for an action.

1st. I.e

Code: Select all

F1::
	...
return
2nd.

Code: Select all

ApplyNewHotkey:
    GuiControlGet, OutputVar, , SSHotkey ; SS Hotkey is the "Hotkey" GUI control.
    keybind := OutputVar
    
    Hotkey, %OutputVar%, HOTKEYACTION ; when pressing the hotkey, do some action
return

HOTKEYACTION:
	...
return
OK! Knowing that, I just want to know if there is any way to use hotkeys with variables.
Something like:

Code: Select all

var := "v"
%var%::
	...
return
or

Code: Select all

var := "v"
%var%:
	...
return
That's it.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Can I use variables as normal labels or hotkey labels?

Post by mikeyww » 06 Dec 2021, 08:20

Code: Select all

var := "v"
Hotkey, %var%, Routine
Gosub, %var%

v::
Routine:
MsgBox, %A_ThisLabel%
Return

User avatar
fx_spencer
Posts: 6
Joined: 06 Dec 2021, 07:45
Contact:

Re: Can I use variables as normal labels or hotkey labels?

Post by fx_spencer » 06 Dec 2021, 08:50

Hello mikey! Thank you for the fast reply but...
Sorry for the misundertand that I got, can you explain the code better? Thank You!

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Can I use variables as normal labels or hotkey labels?  Topic is solved

Post by mikeyww » 06 Dec 2021, 09:09

Code: Select all

var := "v"
Hotkey, %var%, Routine ; Pressing v will execute a subroutine called "Routine"
Gosub, %var%           ; Execute the subroutine called "v"

v::
Routine:
MsgBox, %A_ThisLabel%  ; Display the subroutine label that was called; it's either "v" or "Routine"
Return

Post Reply

Return to “Ask for Help (v1)”