UA - Some small tweaks to improve results for new users.

Post your working scripts, libraries and tools for AHK v1.1 and older
sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

UA - Some small tweaks to improve results for new users.

Post by sashaatx » 08 Feb 2023, 08:13

UIAutomation is tough. I was going to start by building a tool side by side with UIAViewer, and figured its just easier diving into an edit of the original.
All credit for the original goes to: https://github.com/Descolada/UIAutomation <<

my modded code generator:
https://github.com/samfisherirl/UIAViewer.ahk-for-UIAutomation.ahk

edit: Caveat, I love the UIAViewer original solution, I only want to build on it because my frustration all root in my previous lack of knowledge and not the tool's pitfalls.

Problems I had with UIAViewer (I love the tool, but these can be challenging for new users):

1- Too specific. 99% of the time, if I want target VSCode, or Notepad, the concern of the class, title, etc for multiple windows I BELIEVE is down stream as a new user, from just trying to get UIAutomation to work. Once you get it working, which can take hours, then you can worry about multiple windows. Notepad, Chrome, VSCode, they all include document or page details in teh title and that muddies up results (especially for ametuer users).

2 - Defaults are set to case sensitive, exact title match, and waitelementexist. I find this also to be downstream from where new users should be entering. New users should be setup with a try{} catch e{} matchmode=2 and findallby or findfirstby.

The most discouraging thing was the dozens of hours spent pouring over documentation, not knowing that a simple title or window change rendered a code inoperable.


These are just opinions and to this day, a bit of chip on my shoulder for why I wanted to make some changes.

This was all done in the last couple days, I'll outline changes, and take feedback as well as continue to work on other things and todos. Please let me know of any mistakes.


changes:
- if title > 20 characters, it splits by "-", most popular windows split "%document_name% - %program_name%"
- WinExist reduced to not include class
- Try Catch added for FindAllBy
- Remove Defaults of WaitElementExist and Match Case Sensitive

later today and this week Ill be adding:
- Robust notes for new users, including comments on each line
- options to drill down or loop through just a given control
- credit to the original creator (sorry I will add asap)
- more ideas flowing



The [1] is going to be for findallby which I will be changing. Please ignore for now.
Image

new code (subsection which includes changes to the macro creator only)

Code: Select all

		if (MacroFunction != "No function") {
			RegexMatch(MacroMatchMode, "\d(?=:)", match)
			MacroContent .= ",," (match ? (match=3 ? "" : match) : "RegEx") ","
			MacroContent .= (CaseSensitive ? "" : "False") ","
			MacroContent .= StrReplace(MacroTimeout, " ") = "10000" ? "" : MacroTimeout ","
			MacroContent := MacroFunction "(" MacroContent ")"
			MacroContent := RegexReplace(MacroContent, ",*\)$", ")")
			if MacroElementName
				MacroContent := MacroElementName " := " . MacroElementName . "." MacroContent
			if (MacroAction = "SetValue")
				MacroContent .= ".Value := """ DDLMacroActionValue """"
			else if (MacroAction != "Do nothing")
				MacroContent .= "`n" . "try {`n " . MacroElementName . "[1]." MacroAction (SubStr(MacroAction, 0, 1) = ")" ? "" : "()") "`n}`n catch e{ `n" . MacroElementName . "." MacroAction (SubStr(MacroAction, 0, 1) = ")" ? "" : "()`n}")
		}
		
		if (Stored.WinClass != "#32768") && !(RegexMatch(ReverseContent(PreviousContent), "m`n)WinExist\(""(.*) ahk_exe (.*) ahk_class (.*)""\)$", match) && (match1 = Stored.WinTitle) && (match2 = Stored.WinExe) && (match3 = Stored.WinClass)) {
			WinGet, dl, ID, Stored.WinTitle
			wingetter=
			(LTrim
			 WinGet, %MacroElementName%, ID, 
			)
			if (StrLen(Stored.WinTitle) > 20) ;if title is more than 20 characters
			{
				try { 
					ar := StrSplit(Stored.WinTitle, "-")
					indx := ar.MaxIndex()
					Stored.WinTitle := ar[indx]
				}
			}
			
			wingetter .= " " . Stored.WinTitle "`n"
			MacroContent := wingetter
			 . "WinActivate, ahk_id %" . MacroElementName .  "%`n"
			 . "WinWaitActive, ahk_id %" . MacroElementName . "%`n" 
			 . MacroElementName " := UIA.ElementFromHandle(" MacroElementName ")`n`n"
			 . MacroContent

		}


new code in totality doesnt fit so here it is on the git. https://github.com/samfisherirl/UIAViewer.ahk-for-UIAutomation.ahk/blob/main/UIAViewer.ahk


here's the section fo original code that got changed.

Code: Select all

~PrintScreen::
	global DDLMacroActionValue
	Gui Main: Default
	GuiControlGet, FocusedTab,, TabsMain
	if (FocusedTab != "Macro creator")
		return
	if IsObject(Stored.Element) {
		GuiControlGet, PreviousContent,, EditMacroContent
		GuiControlGet, MacroFunction,, DDLMacroFunction
		GuiControlGet, MacroMatchMode,, DDLMacroMatchMode
		GuiControlGet, CaseSensitive,, CBMacroCaseSensitive
		GuiControlGet, MacroElementName,, EditMacroElementName
		GuiControlGet, MacroTimeout,, EditMacroTimeout
		GuiControlGet, MacroAction,, DDLMacroAction
		MacroContent := """ControlType=" UIA_Enum.UIA_ControlTypeId(Stored.Element.CurrentControlType) ((elName := Stored.Element.CurrentName) ? " AND Name='" SanitizeInput(elName) "'" : "") ((elAID := Stored.Element.CurrentAutomationId) ? " AND AutomationId='" SanitizeInput(elAID) "'" : "") """"
		
		
		
		
		if (MacroFunction != "No function") {
			RegexMatch(MacroMatchMode, "\d(?=:)", match)
			MacroContent .= ",," (match ? (match=3 ? "" : match) : "RegEx") ","
			MacroContent .= (CaseSensitive ? "" : "False") ","
			MacroContent .= StrReplace(MacroTimeout, " ") = "10000" ? "" : MacroTimeout ","
			MacroContent := MacroFunction "(" MacroContent ")"
			MacroContent := RegexReplace(MacroContent, ",*\)$", ")")
			if MacroElementName
				MacroContent := MacroElementName "." MacroContent
			if (MacroAction = "SetValue")
				MacroContent .= ".Value := """ DDLMacroActionValue """"
			else if (MacroAction != "Do nothing")
				MacroContent .= "." MacroAction (SubStr(MacroAction, 0, 1) = ")" ? "" : "()")
		}
		if (Stored.WinClass != "#32768") && !(RegexMatch(ReverseContent(PreviousContent), "m`n)WinExist\(""(.*) ahk_exe (.*) ahk_class (.*)""\)$", match) && (match1 = Stored.WinTitle) && (match2 = Stored.WinExe) && (match3 = Stored.WinClass)) {
			MacroContent := MacroElementName " := WinExist("""Stored.WinTitle " ahk_exe " Stored.WinExe " ahk_class " Stored.WinClass """)`n"
			 . "WinActivate, ahk_id %" MacroElementName "%`n"
			 . "WinWaitActive, ahk_id %" MacroElementName "%`n" 
			 . MacroElementName " := UIA.ElementFromHandle(" MacroElementName ")`n`n"
			 . MacroContent

		}
		GuiControl,, EditMacroContent, % PreviousContent ? PreviousContent "`n`n" MacroContent : MacroContent
	}
	return
Attachments
image.png
image.png (100.97 KiB) Viewed 1750 times
Last edited by sashaatx on 17 Feb 2023, 21:33, edited 7 times in total.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

Descolada
Posts: 1098
Joined: 23 Dec 2021, 02:30

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by Descolada » 08 Feb 2023, 11:31

@sashaatx, I would like to share a couple of thoughts:
UIAutomation is tough. I was going to start by building a tool side by side with UIAViewer, and figured its just easier diving into an edit of the original.
All credit for the original goes to: https://github.com/jethrow/UIA_Interface
UIAutomation is hella tough, and unfortunately my implementation of UIA_Interface.ahk is/was rather lacking in multiple aspects. Confusing syntax, too little errors etc, some of which of these problems I've tried to address with UIA v2 for AHK v2, so you might want to check that out and give some feedback :)
And while UIA_Interface is built on jethrow's UIA_Interface, UIAViewer is completely written by me.
1- Too specific. 99% of the time, if I want target VSCode, or Notepad, the concern of the class, title, etc for multiple windows I BELIEVE is down stream as a new user, from just trying to get UIAutomation to work. Once you get it working, which can take hours, then you can worry about multiple windows. Notepad, Chrome, VSCode, they all include document or page details in teh title and that muddies up results (especially for ametuer users).
While that is true, the tree is rather important in understanding how UIA works and how the elements are related to eachother. The macro creator can very well spit out code that doesn't work at all, so even the beginner user has to debug it somehow, and that means understanding that FindFirst searches the displayed tree using the displayed properties as search criteria.
2 - Defaults are set to case sensitive, exact title match, and waitelementexist. I find this also to be downstream from where new users should be entering. New users should be setup with a try{} catch e{} matchmode=2 and findallby or findfirstby.
The defaults are set to that for a reason. First, you don't need to worry about case sensitivity or matchmode, because you can copy-paste the properties easily. Case-sensitive and exact matching is the most reliable way, because you can easily get multiple matches when using case-insensitive and matchmode=2 and match the wrong element! Also, matchmode=2 and case-insensitive is not supported in some of the older Windows versions, so it might not work for some users.
The most discouraging thing was the dozens of hours spent pouring over documentation, not knowing that a simple title or window change rendered a code inoperable.
Yes, this is an AHK v1 problem. I recommend you try out AHK v2, because there you will get an error instantly.

Finally, about your proposed UIAViewer: currently it doesn't run, because you are including a library which doesn't exist in that GitHub with #Include WinTitleSearch.ahk. Removing that line works.
Also I am quite open to pull requests on my UIA_Interface GitHub page. I am mostly working on UIA-v2 now, so it would help if somebody helped maintain the old one. Though breaking changes (eg FindFirst/FindAll throwing errors when no matches found) would need to wait a bit for a new major release.

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by sashaatx » 08 Feb 2023, 11:50

Descolada wrote:
08 Feb 2023, 11:31
@sashaatx, I would like to share a couple of thoughts:
UIAutomation is tough. I was going to start by building a tool side by side with UIAViewer, and figured its just easier diving into an edit of the original.
All credit for the original goes to: https://github.com/jethrow/UIA_Interface
UIAutomation is hella tough, and unfortunately my implementation of UIA_Interface.ahk is/was rather lacking in multiple aspects. Confusing syntax, too little errors etc, some of which of these problems I've tried to address with UIA v2 for AHK v2, so you might want to check that out and give some feedback :)
And while UIA_Interface is built on jethrow's UIA_Interface, UIAViewer is completely written by me.
1- Too specific. 99% of the time, if I want target VSCode, or Notepad, the concern of the class, title, etc for multiple windows I BELIEVE is down stream as a new user, from just trying to get UIAutomation to work. Once you get it working, which can take hours, then you can worry about multiple windows. Notepad, Chrome, VSCode, they all include document or page details in teh title and that muddies up results (especially for ametuer users).
While that is true, the tree is rather important in understanding how UIA works and how the elements are related to eachother. The macro creator can very well spit out code that doesn't work at all, so even the beginner user has to debug it somehow, and that means understanding that FindFirst searches the displayed tree using the displayed properties as search criteria.
2 - Defaults are set to case sensitive, exact title match, and waitelementexist. I find this also to be downstream from where new users should be entering. New users should be setup with a try{} catch e{} matchmode=2 and findallby or findfirstby.
The defaults are set to that for a reason. First, you don't need to worry about case sensitivity or matchmode, because you can copy-paste the properties easily. Case-sensitive and exact matching is the most reliable way, because you can easily get multiple matches when using case-insensitive and matchmode=2 and match the wrong element! Also, matchmode=2 and case-insensitive is not supported in some of the older Windows versions, so it might not work for some users.
The most discouraging thing was the dozens of hours spent pouring over documentation, not knowing that a simple title or window change rendered a code inoperable.
Yes, this is an AHK v1 problem. I recommend you try out AHK v2, because there you will get an error instantly.

Finally, about your proposed UIAViewer: currently it doesn't run, because you are including a library which doesn't exist in that GitHub with #Include WinTitleSearch.ahk. Removing that line works.
Also I am quite open to pull requests on my UIA_Interface GitHub page. I am mostly working on UIA-v2 now, so it would help if somebody helped maintain the old one. Though breaking changes (eg FindFirst/FindAll throwing errors when no matches found) would need to wait a bit for a new major release.


as a caveate, nothing I said was an indictment of your application, before I decided to fullstack develope, things like arrays, dictionaries, json, all that stuff was alien until my career change. Things needed as a prerequisite to use UIAutomation. All the work you put in, I admire it greatly.
I appreciate the offer and would be more than glad to mock up things for a updated release. All of this was slammed together in one night after toying with ideas over the last week, I have a lot more testing and such to do, Im glad Im not posting to the void and that was my main concern. Ensuring someone out there would use it lol.


as far as autohotkey V2 I think it has a very tough Hill to climb. I'm a bit tired so again I'm being a bit forthright and that may be a detriment to my rhetoric so understand I mean all of this with love for the language otherwise I wouldn't spend so much time here. Id love to get your thoughts and maybe have you do a bit of selling because Im afraid I have a tough time considering v2.



I think fundamentally Auto hotkey V2 has a flawed premise and I'll explain my thoughts. If we were to bucket Auto hotkey users into three kinds of people I would say people who only swap keys and maybe a little more and probably only know how to copy other people's code in one line increments.



Then There are people who are bordering on development, thinking about doing it full time, and then we'll say the older generation who's been using Auto hotkey forever probably right C plus plus or doesn't write a language at all.

I won't speak on actual developers because they can use any language they want .

I would say very strongly and I'm willing to be moved on this, it is from my perspective it would be ill advise to try to learn version two of auto hotkey.



Now I know I'm saying this literally in the worst place possible to say this so I'm going to try to justify it and I mean it with love.



If I'm person A and I copy other people's code there's literally no reason to use version 2, I just want to swap keys and it does that just fine.



person B who is borderline on developing or thinking about it or maybe young and has a future in development, but they don't know a full language. I would say it's ill-advised for that person to do anything but learn a full programming language a c or Java or python.



The developer Who develops full-time already has access to all of these tools and auto hotkey is just a short hand and I would say I'm in that camp, I just have no reason to other than what's already in my existing trunk of knowledge to learn a second shorthand to do the exact same thing.

my time is better spent learning C# or C++ legitimately

Maybe that's just me. And of course the older generation that's been playing around with autohotkey for 5 to 10 years whether they develop if they develop they're an old dog they don't want to learn something new. If they don't develop learn version to unless there's not a whole lot going on.



This is my thesis on why I think version 2 of key is a very very Niche solution and almost ill advised for anyone but that niche group. but good on the developers I love them and adore them this is the language that got me interested in development I'll never second guess their decisions other than posit my own opinions. I think we can all agree if someone is teetering on taking a career and development they should stick with learning a true language and not version 2. Love to get your thoughts.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by sashaatx » 11 Feb 2023, 06:19

Image



updated function-based output
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by boiler » 11 Feb 2023, 14:21

sashaatx wrote: ...but they don't know a full language. I would say it's ill-advised for that person to do anything but learn a full programming language a c or Java or python.
...
I think we can all agree if someone is teetering on taking a career and development they should stick with learning a true language and not version 2.
I agree that if you're looking for a career in programming, you are much more marketable learning one of the other languages, but I don't see how you can characterize AHK as less than a "full" or "true" language. What basis do you have for that other than popularity? Just poor word choices?

By the way, what's the reason for posting big screenshots of code from your editor? How is posting it in a code box not sufficient? It makes it a pain when scrolling through the thread. I'll ask that you not do that anymore.

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by sashaatx » 12 Feb 2023, 07:47

boiler wrote:
11 Feb 2023, 14:21
sashaatx wrote: ...but they don't know a full language. I would say it's ill-advised for that person to do anything but learn a full programming language a c or Java or python.
...
I think we can all agree if someone is teetering on taking a career and development they should stick with learning a true language and not version 2.
I agree that if you're looking for a career in programming, you are much more marketable learning one of the other languages, but I don't see how you can characterize AHK as less than a "full" or "true" language. What basis do you have for that other than popularity? Just poor word choices?

By the way, what's the reason for posting big screenshots of code from your editor? How is posting it in a code box not sufficient? It makes it a pain when scrolling through the thread. I'll ask that you not do that anymore.
Ahk is the reason I started to love development and I brought all of this together in a philisophical sense. You seem to be taking things personally. Im not hear to offend, but if questioning the philosophy of the creators gets me ire from mods, maybe I should see myself out.

m8, You seem to be attacking my ability to form sentences, a bit ableist but probably an honest mistake.

I posted the screen shot because the code is generated without code highlighting and I cant read code without it. I didnt expect it to be 4k resolution, I wont do it again m8.

> but I don't see how you can characterize AHK as less than a "full" or "true" language

I think by the first half of your sentence, you understood what I meant. In the second half you seem to drop that understand to bicker about semantix. I think we're on the same page, poor word choice or not. Full language isn't an official defined industry-term. There for an abiguous definition is understandable.

If you were to describe languages that have general direct appeal in the market for potential jobs, and languages that arent on any job requirement anywhere, I would say when I used full language, that's what I meant.

Thats not a bullet proof definition, either way, light displayed on your monitor that originated from my keyboard and I believe you understand when you saw that light, that autohotkey (v1) has differences from javascript, java, c++, C#, py, etc. To breakup languages into two halfs isnt unreasonable but again, I think you get the underlying meaning and the definition isnt important.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by boiler » 12 Feb 2023, 11:55

sashaatx wrote: You seem to be taking things personally…You seem to be attacking my ability to form sentences, a bit ableist but probably an honest mistake. …
If you were to describe languages that have general direct appeal in the market for potential jobs, and languages that arent on any job requirement anywhere, I would say when I used full language, that's what I meant.
No ire nor attacking nor taking anything personally here at all. You seem to be taking it personally by accusing me of being ableist when I was just asking for clarification specifically about AHK. So the mistake is on your part for making it explicitly personal where I had done nothing of the sort.

It looks like you are confirming that I was right in that you really meant more popular, just as I assume you wouldn’t consider English and Spanish real or full languages as compared to Greek or Swedish — merely more popular.

Please don’t continue this off-topic discussion further. I asked a matter-of-fact question about opinions you offered on AHK, then you took it somewhere else. I had to reply since you accused me of making it personal before you then actually did so yourself.

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by sashaatx » 13 Feb 2023, 03:03

boiler wrote:
12 Feb 2023, 11:55
sashaatx wrote: You seem to be taking things personally…You seem to be attacking my ability to form sentences, a bit ableist but probably an honest mistake. …
If you were to describe languages that have general direct appeal in the market for potential jobs, and languages that arent on any job requirement anywhere, I would say when I used full language, that's what I meant.
No ire nor attacking nor taking anything personally here at all. You seem to be taking it personally by accusing me of being ableist when I was just asking for clarification specifically about AHK. So the mistake is on your part for making it explicitly personal where I had done nothing of the sort.

It looks like you are confirming that I was right in that you really meant more popular, just as I assume you wouldn’t consider English and Spanish real or full languages as compared to Greek or Swedish — merely more popular.

Please don’t continue this off-topic discussion further. I asked a matter-of-fact question about opinions you offered on AHK, then you took it somewhere else. I had to reply since you accused me of making it personal before you then actually did so yourself.
First I'd like to apologize for both speaking off topic and suggesting your language having ableist connotations.

I feel there's more to the story and have invited a third party to hopefully help me get some insight into either my actions or our actions.
I reached out to admins but haven't heard back (it's Sunday, that's fair) but what you did was really hurtful. I just want to describe what happened.

I'm autistic and you gave me a strike on my account because I said I felt like there was a bit of ableism but I also said it was probably an honest mistake.

I never meant for my language to come off as either hurtful or hateful. I apologize again. But in my appeal to the mods and admins, I'd like to share from my perspective what I thought I saw happen. Boyle joined in the discussions, perpetuated it, got his final word in, told me to stop off topic discussion he was party to and struck my account. The topic was how this tool integrates with autohotkey 2 and I went off on a bit of a tangent.

Clearly I have some blame in this and I will apologize for both suggesting your language was ableist and for going off topic.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by boiler » 13 Feb 2023, 07:11

sashaatx wrote: I'm autistic and you gave me a strike on my account because I said I felt like there was a bit of ableism but I also said it was probably an honest mistake.
I accept your apology. What I said was neither ableist nor a mistake. You will have no problem with a warning on your account as long as you stay on topic going forward.

PaigeDown
Posts: 19
Joined: 24 Dec 2022, 15:26

Re: UIAViewer.ahk - Some small tweaks to improve results for new users.

Post by PaigeDown » 16 Feb 2023, 17:34

first impression, woah!!
second impression.. yikes...
third impression, woah!!
this is awesome, I just tried it out, I see so much potential with this, it wouldn't work to click my target, but just that it can read it is impressive! excited to see where this goes!

Post Reply

Return to “Scripts and Functions (v1)”