Simplifying external hotkey .ini files ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Simplifying external hotkey .ini files ?

Post by mikeyww » 10 Jun 2021, 19:23

Here it is.

Code: Select all

Left = x
Thisisabrandname = y
Thisisamodelname = z
Sx1 = Left
Device1 = Thisisabrandname
Device2 = Thisisamodelname
Part := []
Part[1] := "ToggleStuff"
Part[2] := "Sx1"
Part[3] := "Device1"
Part[4] := "Device2"
MsgBox, 64, Result, % callIt(Part) "`n" ToggleStuff(Left, Thisisabrandname, Thisisamodelname)

callIt(arr) {
 new := [], function := arr.RemoveAt(1)
 For k, v in arr
  part := %v%, new.Push(%part%)
 Return %function%(new*)
}

ToggleStuff(a, b, c) {
 Return a b c
}
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Simplifying external hotkey .ini files ?

Post by Jose Hidalgo » 11 Jun 2021, 17:18

I don't understand why you're doing this.

Every time you reply, you give a solution that will work in your particular example, but that won't work in my script.
Your last example works because you're not using hotkeys. My code uses hotkeys and labels. See the difference ?

You know perfectly my code. I have posted it many times in this topic. It's a very simple code.
That code uses a hotkey command which needs to call a label. A LABEL. It can't call a function, because as far as I understand, that's forbidden : https://www.autohotkey.com/docs/commands/Hotkey.htm
That's why I've been using the TakeAction label since forever.

Now you are posting a new-new-new example (II won't call it a solution, just an example), and for unknown reasons, you took the liberty of transforming the TakeAction label into a callIt FUNCTION. So my hotkey command can't call it anymore. Why would you do that ? I don't know. :cry:

I'm getting tired of this. I had a working mechanism and I was happy with it, but you said it could be improved by reducing the number of IniReads.
I could have said "I don't care", but since I think of all the people that are going to use my code, I'd like it to be as efficient as possible. For THEM, not for me.

So I've swallowed my pride and asked your help once again (asking help repeteadly is not easy, you know). I have explained very precisely what my code was and how it worked (in case it wasn't clear enough).
And instead of simply adapting my code, you keep on answering with yet another example that CAN'T EASILY BE TRANSPOSED TO MY CODE !!! Why are you doing this ???
Was it too much to ask that you simply corrected the TakeAction label, like I explicitly requested in my last post ?
Jose Hidalgo wrote:
10 Jun 2021, 18:01
The only part that needs to be modified is TakeAction, so it generates the proper code to call each function with the right arguments. Just like it does right now with the previous non-optimized version of the code.
I am an absolute beginner in AHK world. I think everybody here knows that. Every one of your posts makes me feel even more beginner, which I believe is not their intended purpose. Or is it ?
And yet I've managed to pull out a script that's currently 2.500 lines long and WORKS. Giving it several months of my life when nothing is forcing me to. Just to help others. I don't think a lot of people could do that for their first script.
Maybe that deserves a little more appreciation, support and understanding. Not just examples that can't be transposed, like puzzle pieces that don't fit.

I don't know. I'm not expecting anything at this point. Just strongly disappointed, that's all. :cry:
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Simplifying external hotkey .ini files ?

Post by mikeyww » 11 Jun 2021, 18:27

You're right. I didn't pay enough attention to the earlier posts. I was just responding to the most recent one in a blinded way. And yes, I was showing an example. Sorry to have disappointed. As I indicated, if both scripts work, use either. I crafted a function because I believed that it would directly address your need. If it didn't address your need, then OK, my approach did not work for you. You have the power to use examples that readers provide here, or not use them. I'll let others take over from here.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: Simplifying external hotkey .ini files ?

Post by Jose Hidalgo » 11 Jun 2021, 20:04

I knew you would say that. Which is why I made sure I had found the solution before I posted my previous reply.

This code works : your previous IniRead part (thanks for that, I guess) with a microscopic adaptation my old TakeAction label (credits to Smile_, whose help has been unbelievable all along).
One line. It was THAT easy. Me, it took me hours to find it, but that's normal. I'm a beginner, for God's sake !

Here's for future readers. At least I think about them.

Code: Select all

Action := []
INIHotkeys := "Hotkeys " Layout ".ini"
IniRead, HotkeysSection, %INIHotkeys%, Hotkeys
Loop, Parse, HotkeysSection, `n, `r
{
  part := StrSplit(A_LoopField, "=")
  IniRead, Command, %INIHotkeys%, Commands, % part.2
  Action[part.1] := Command
  Hotkey, % part.1, TakeAction
}
and

Code: Select all

TakeAction:
  part := StrSplit(Action[A_ThisHotkey], ",")
  For K, V in part
    (K = 1) ? (Para_%k% := V) : (!InStr(V, "%") ? (!RegExMatch(V, "[^0-9]") ? Para_%k% := V : (!InStr(V, """") ? ((!InStr(V, ".") && !InStr(V, "-")) ? Para_%k% := %V% : Para_%k% := V) : Para_%k% := Trim(V, """"))) : (Position := RegExMatch(V, "%.*%", OutVar), VarName := SubStr(OutVar, 2, StrLen(OutVar) - 2), Mod := RegExReplace(V, "%.*%", ""), tmp := %VarName%, tmp_ := tmp Mod, Para_%k% := %tmp_%))
  %Para_1%(Para_2, Para_3, Para_4, Para_5, Para_6, Para_7)
Return
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Simplifying external hotkey .ini files ?

Post by boiler » 12 Jun 2021, 02:00

Jose Hidalgo wrote: That code uses a hotkey command which needs to call a label. A LABEL. It can't call a function, because as far as I understand, that's forbidden : https://www.autohotkey.com/docs/commands/Hotkey.htm
If you took the time to read the documentation page of the link you provided in your scolding reply, you would see it can call a function. A FUNCTION. Here is an excerpt from the very section you were referring to:
If not a valid label name, this parameter can be the name of a function, or a single variable reference containing a function object.

Jose Hidalgo wrote: Now you are posting a new-new-new example (II won't call it a solution, just an example), and for unknown reasons, you took the liberty of transforming the TakeAction label into a callIt FUNCTION. So my hotkey command can't call it anymore. Why would you do that ? I don't know. :cry:
Not correct.

Jose Hidalgo wrote: I'm getting tired of this...And instead of simply adapting my code, you keep on answering with yet another example that CAN'T EASILY BE TRANSPOSED TO MY CODE !!! Why are you doing this ???
Wrong again.

Jose Hidalgo wrote: I don't know. I'm not expecting anything at this point. Just strongly disappointed, that's all. :cry:
I am strongly disappointed to see this type of reply to someone who is spending their own time, uncompensated in any way, to help a very unappreciative stranger who repeatedly berates them for the form of that help. As was pointed out, if you don’t like a reply, you can simply ignore the post. I also often post my responses in the form of examples, leaving it to the OP to learn from that example and apply the concept to their own code. Perhaps if you were paying for the help, you might demand the help be provided in a certain form, but no amount of money would get me to put up with these types of replies.

Remember that other members of the forum see these posts as well and will make their decisions about whether to try to help the person who posted them in the future. You can probably guess what I have decided.
Post Reply

Return to “Ask for Help (v1)”