How to write the script with a variable class?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

How to write the script with a variable class?

Post by necomerx » 13 Jan 2021, 01:06

Hi,
I'm seeking for help again for a script that include a class name that change slightly. I think that i have to introduce a variable at the part that is changing but can't figure out how to do it. I have done a load of researches without finding the solution, so if a more knowledgable person than me could help, that would be great.

Thanks in advance
Last edited by necomerx on 28 Jan 2021, 07:26, edited 1 time in total.

HeroOfKvatch
Posts: 15
Joined: 11 Sep 2017, 23:47

Re: How to write the script with a variable class?

Post by HeroOfKvatch » 13 Jan 2021, 01:43

Hi, I'm no expert with AHK classes, but why do you need a variable class?

Isn't easier to just create a new instance of a class? Or give the classes a property that you can use to trigger certain code.

Code: Select all

self.uniqueID := 'whatever you throw in here'
If you initialize the class with such a variable, you can trigger conditions within the class. Depending on your use case it might not be the prettiest solution, but in python this would work. I'm guessing AHK works about the same way with classes.

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to write the script with a variable class?

Post by necomerx » 13 Jan 2021, 08:40

Hi, Thanks for your reply.
Do you think that the self.uniqueID gonna be the solution? Can you give me an example with my script because i still have a lot to learn in Autohotkey and don't know how to do that
Last edited by necomerx on 28 Jan 2021, 07:30, edited 1 time in total.

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: How to write the script with a variable class?

Post by WatsonEnterprises » 13 Jan 2021, 20:11

necomerx wrote:
13 Jan 2021, 01:06
The part "JUCE_176f9" is always the same. That's what's after that, that change.
https://www.autohotkey.com/docs/commands/SetTitleMatchMode.htm wrote:"RegEx also applies to ahk_class and ahk_exe; for example, ahk_class IEFrame searches for any window whose class name contains IEFrame anywhere."
You've already added "SetTitleMatchMode, RegEx", which should accomplish your goal (assuming the window class name always starts with JUCE_176f9xxxxx as you mentioned above). But it looks like you forgot to change the text in "#IfWinActive", since it still says "JUCE_176f9c1b56c" instead of "JUCE_176f9".

If you wanted, you might also be able to just do "#IfWinActive, ahk_exe FL64.exe" instead of using ahk_class, assuming all your plugins are running from FLStudio's exe.

necomerx
Posts: 57
Joined: 01 Jan 2021, 09:09

Re: How to write the script with a variable class?

Post by necomerx » 14 Jan 2021, 09:11

Thanks for your reply. It is solved. I didn't know that I have to keep only what's not changing. I don't use the ahk_exe because I still need the space bar in FL studio when typing text. I try instead using that in the line "winactivate, FL Studio 20" but for a reason I don't know, it didn't work

Post Reply

Return to “Ask for Help (v1)”