Use title id with array

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 550
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Use title id with array

26 Dec 2022, 07:18

I have an array that contain many window id.
I need to use WinGetTitle with that array, without assign the window id to a variable:
WinGetTitle, OutputVar, ahk_id array[1] <- no works
WinGetTitle, OutputVar, ahk_id % array[1] <- no works
WinGetTitle, OutputVar, ahk_id %array[1]% <- no works

iTest := array[1]
WinGetTitle, OutputVar, ahk_id %iTest% <- works, but I no like it. I need the quickest work as possible, then I need only one line work.

Do you have any idea about it?
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 07:24

Code: Select all

#Requires AutoHotkey v1
arr := []
arr.Push(hWnd := WinExist("ahk_exe notepad.exe"))
WinGetTitle title, % "ahk_id" arr.1
MsgBox 64, Title, % title
Explained: Force an expression
Force an expression: An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. In [v1.1.21+], this prefix can be used in the InputVar parameters of all commands except the traditional IF commands (use If (expression) instead). This technique is often used to access arrays.
For a given parameter, you cannot mix literal strings with expressions; you pick one or the other. Thus, to access an array, the entire parameter must be an expression.

Code: Select all

#Requires AutoHotkey v2
arr := []
arr.Push(hWnd := WinExist("ahk_exe notepad.exe"))
title := WinGetTitle('ahk_id' arr[1])
MsgBox title, 'Title', 64
Archimede
Posts: 550
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Use title id with array

26 Dec 2022, 07:33

Interesting, thank you very much.
The v2 is very interesting, but I began the program with the v1.1 then I think to continue with that version.
Where I can found help about the use of % like you show me for the v1.1?
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 07:37

You can find it at the AutoHotkey documentation page that I cited in my post. The link is blue and has underlined text.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 09:22

mikeyww, please help me understand why the "title" variable apparently contains two different types of information, as it appears in the message MsgBox 64, Title, % title and why in the first part you don't need the percentage symbol (%)
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 09:32

AutoHotkey command parameters accept literal strings instead of expressions by default, but you have the option to force an expression if you wish. This is explained on the page that I have mentioned twice in this thread.

Code: Select all

test := "Test"
MsgBox, tossed
MsgBox, % "tossed"
MsgBox, %test%
MsgBox, % test
msgboxTitle := "This is the MsgBox title."
msgboxText  := "This is the MsgBox text."
MsgBox, 64, This is the MsgBox title, %msgboxText%
MsgBox, 64, % msgboxTitle, % msgboxText
In the earlier "Title" example, the first use of "Title" is a literal string that represents the MsgBox's title. The subsequent parameter refers to a variable named title.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 10:35

I hadn't realized that the MsgBox command could have a name (I haven't read AutoHotkey's help, I only refer to it when I need it —AutoHotkey for me is just a means to entertain myself, not an end, as it is for programmers— and how the brain goes to what it "seeks", ignores the rest of the information). Why does it "inherit" the name of the forced expression? (Why yes, :lolno:, because that's what the script says. According to what I read in the help, failing that, it inherits the name of the script).

Offtopic. I think that those of you who know a lot sometimes "exceed" your examples (to the extent that you "confuse" people who are starting out). It is enough to "digest" how it is stored in an array, to also make the message show its name. This is not a complaint, but constructive criticism. I hope you understand me.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 11:35

I posted the simplest example and explanation that I could devise to answer your question. If you have better ones, please post them so that we can learn from them. If you're not going to read what's actually posted, then you're wasting your own time with your post! The documentation can be helpful at times.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 12:09

mikeyww. Good vibes. :thumbup:

The script you posted could serve me well for a screenplay, but I had to understand it in order to apply it. I was confused by the line MsgBox 64, Title, % title, which gives the same result if you just put MsgBox, %title%

(I have already said other times that the help, in most cases, is written for people who have a certain level of prior knowledge. Sometimes they do not have good and simple examples, but complex ones that already require a certain level of knowledge (it is It jumps to explaining square roots, without teaching addition, subtraction or division, so that I am understood. From my point of view, it would have to be rewritten. Another problem is that it is in English, since if it is translated with Google, the order changes of the phrases —or mixes expressions and commands for words in use— and, in many cases, the message is lost.)

I'm ignorant in programming and I don't see myself able to help, except in simple cases. I go in above all to learn from the examples (and I do read the help if it refers to it, if necessary).
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 12:37

Thank you for the explanation. My opinion is that my MsgBox (as displayed) is more informative, because it provides not only the content, but a description of what the content is: the title. This is typically how I use the MsgBox in my own scripts for myself. Nonetheless, I can see and appreciate your point that the code itself is simpler in the shorter way that you wrote it, without a descriptive MsgBox title.

I often do post scripts that require either some knowledge or some reading and new understanding, and I don't provide a lot of comments in the scripts that I post. It's a learning exercise for the reader. For me, that's what I like as a reader and someone who has a question, when I have a question. I want to see a post, and try to figure out what the code does. At the same time, many other readers actually don't care what the script means; they just want to run it and have it work. In those cases, it doesn't matter how complicated the script is. For those who do want to understand the script, we are here to answer questions, clarify, etc. The other reality is that people have different baseline levels of knowledge, but the responder often has no idea what that level is, so the reader's job is to read the entire reply carefully, and ask questions whenever needed. :thumbup:

I get some replies that say, "Treat me like I'm five years old" (yes, that is actually what some people write), and others that say, "Don't treat me like I'm five years old." :morebeard:

Now back to my screenplay....
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 13:35

Hi.

I'm getting bored (I'm bored, in this case, it's because I have nothing else to do and I've also studied philosophy). I'm going to give a little speech. "Victor of Aveyron (French: Victor de l'Aveyron; c. 1788 – 1828) was a French feral child who was found at the age of around 9. Not only is he considered the most famous feral child, but his case is also the most documented case of a feral child. Eventually his case was taken up by a young physician, Jean Marc Gaspard Itard, who worked with the boy for five years and gave him his name, Victor. —Wikipedia Source https://en.wikipedia.org/wiki/Victor_of_Aveyron—) What Jean Marc Gaspard Itard learned is that a feral child does not learn the concept of categories, surely because learning occurs through certain critical periods of the brain, as also occurs with language (https://en.wikipedia.org/wiki/Critical_period. But this process is only halfway to how the brain works.

A person without teaching may not learn what a verb is, but his brain throughout life will create the concept of a verb through speaking and writing. Since he will differentiate them from other word forms such as prepositions, adverbs or nouns. Does that brain have the category of verb? Yes, although he has not studied it, and perhaps without being able to explain with words what a verb is.

What I want to say is that through good examples, AutoHotkey can be learned, since the brain itself is in charge of creating the categories in an abstract and natural way. As well as having studied it? Surely not, but at a certain age, perhaps, certain abstract concepts of programming are no longer so easy to assimilate, since that brain is no longer in a critical period to create such categories or abstraction levels. (Easier: You can't teach an old dog new tricks).
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 13:44

through good examples, AutoHotkey can be learned
Some yes, some no. Examples are important for learning coding, but they may be insufficient for some types of coding. At least in some cases, where examples might work, a description that explains the coding might save a great deal of time. One may or may not describe coding as strictly about patterns of syntax, but acquiring a complete understanding of syntax might require an enormous amount of time without any descriptions. For example, if I don't know the ASCII code for an infrequently used letter, and I see examples of some other codes, I may or may not be able to determine the new code that I need. I might be able to find it through examining many patterns, and a great deal of trial and error, but a description could save me quite a bit of time. In this sense, any sort of historical knowledge is not necessarily obvious based on a small number of examples of other things that are provided. Coding is largely a logical and patterned activity, but it is also designed by people and has historical attributes that can be difficult to guess and discern. Well, let me just say that AutoHotkey version 1 is a good example? :lol: My favorite example is the Hotkey, If statement, which requires the expression to have already been used elsewhere in the script. If it is not used, then the statement is invalid and will throw an error. I'd say that this fact is almost impossible to guess without reading a description of it. An example might help the reader, but it might not.
At a certain age, perhaps, certain abstract concepts of programming are no longer so easy to assimilate
This varies by person, but it is well known that the brain and its capacity for creativity change significantly with age, starting at a young age. At the same time, the brain itself has no known boundaries in terms of knowledge that it can acquire, and while many individuals find their peak capacity at age 17 or 25, others find it at age 60 or 70. Emotional intelligence is believed to expand continually throughout many lives, and so the dimensions of intelligence are complex in themselves. There are likely to be boundaries of some kind, but no one knows what they are, and no one has ever proven that a brain is now "full", at any point. Therefore, I make no assumptions about what can be learned, and when it can be learned. As for me personally, I have a boundary in coding where I simply haven't had the time to invest the effort in a certain amount of additional learning. I'm unlikely ever to read about how to make a DllCall, but I'm extremely agile with the "Paste" button on my keyboard! :)
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 14:14

What follows only tries to be an example of what I have already said above, in no case do I call you uneducated or something similar. Like me I assume you have the same deference to me.

I could, through what you have said, "determine" the "errors" about epistemology that you fall into, at the level of philosophy. but not parts of
my own knowledge of philosophy, then it would be difficult for me to explain it to you. I could tell you to read this or that author, or about this or that concept, which would refer us to a typical philosophical discussion that would not end when we died, but would be continued by other philosophers.

Yes, it is evident, learning depends on the level of predisposition that each person has. But just as you have (possibly) no interest in philosophy (it doesn't seem like you've read about the critical period, which you have the link above, which is about pedagogy), similarly other people have no interest in programming and just want a script that will works for something very specific. In those cases, the less "frills" a code has, the better.

(It occurs to me that in A.I., they are awkwardly teaching what a cat is through seeing millions of images. The same thing happens with words, without a definition of what a fork is, a child learns what it is. It remains at the level from other professionals or philosophers if a three meter fork is a fork, then it loses one of its attributes: being able to pierce food. Although with a good crane you can pierce a cow, with such a fork. :mrgreen: )

As I said above, which I think is not well translated. It is evident that learning that starts from the explanation of the concepts is better than that other way that the brain has "by default" of creating categories and concepts itself.

I end the dialogue for myself. More than anything because we could spend days and days chatting without reaching something concrete.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 14:23

You are right, I have absolutely no interest in philosophy.
learning that starts from the explanation of the concepts is better than that other way
Some of the first learning that a person ever does is to acquire language. It is done only by hearing it (for those who hear)-- and speaking and seeing it, too-- and generally done perfectly with that alone (aside from learning disabilities)-- for a period of at least a couple of years. Those who learn grammar later often struggle immensely with it, despite being able to speak normally and fluently. Thus, our ability to apply, integrate, use, and absorb an example can be vastly different from our ability to describe and explain it.

If you have ever sat in an immersion language class or course, you would be very unlikely to receive an explanation of the language as a first step.
similarly other people have no interest in programming and just want a script that will works for something very specific. In those cases, the less "frills" a code has, the better.
I would disagree vigorously. For those with no interest in programming, the frills, whether small or large, would often make no difference at all.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 14:52

Some of the first learning that a person ever does is to acquire language. It is done only by hearing it (for those who hear)-- and speaking and seeing it, too-- and generally done perfectly with that alone (aside from learning disabilities)-- for a period of at least a couple of years.
That, in essence, is what "critical period" means. If I have spoken of critical periods, it is to say that at my age —like others due to other circumstances— it is hardly going to be of little or nothing to me to explain the help of Autohotkey. Above all because, in many cases, they "speak" for those who start from other concepts already learned. In other words, for people who already have knowledge —and/or interest— in programming.
Those who learn grammar later often struggle immensely with it, despite being able to speak normally and fluently. Thus, our ability to apply, integrate, use, and absorb an example can be vastly different from our ability to describe and explain it.
What you have said serves at the same time to differentiate between wisdom (a person's knowledge) and the ability to teach. They don't have to go hand in hand.
I would disagree vigorously. For those with no interest in programming, the frills, whether small or large, would often make no difference at all.
I have a script of more than 2000 lines and "reading it" now I see that "excess" things are not "useful" for anything, that at the time I put them to follow an example. But I no longer feel like going through the entire script from top to bottom, trying to erase all that possibly unnecessary stuff. I don't think it happens only to me. Over the years almost all programs have junk code.
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Use title id with array

26 Dec 2022, 15:47

True, but stop reading the script! That's only for people who really want the details.

:) ;)

I can teach, but I'm not wise. Or maybe it's the opposite? Or neither.
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Use title id with array

26 Dec 2022, 16:28

We've already spent the afternoon. The main thing is to feel alive and be active in life, instead of passive watching TV. :D ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], macromint, peter_ahk and 334 guests