AHK use UIA (inspect) get the text problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

AHK use UIA (inspect) get the text problem

Post by Lo4438 » 12 Aug 2022, 12:01

Anybody can help me.

How to write the code to get the text from (inspect) LegacyIAccessible. Value.

Please see the picture.
Attachments
Screenshot_2022-08-13-01-01-17-96_6012fa4d4ddec268fc5c7112cbb265e7.jpg
Screenshot_2022-08-13-01-01-17-96_6012fa4d4ddec268fc5c7112cbb265e7.jpg (227.2 KiB) Viewed 1379 times

teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: AHK use UIA (inspect) get the text problem

Post by teadrinker » 12 Aug 2022, 15:48

Try this:

Code: Select all

ControlGetText, text, RichEdit20W1, Inspect
RegExMatch(text, "LegacyIAccessible\.Value:\t\K\V+", m)
MsgBox, % m

Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

Re: AHK use UIA (inspect) get the text problem

Post by Lo4438 » 12 Aug 2022, 21:56

Thanks for your reply.

If I want get more texts from multiple positions, how to put your code in my script??

Code: Select all

#Include uia.ahk
$u:=new IUIAutomation
$e:=new IUIAutomationElement
$c:=new IUIAutomationCondition
$r:=new IUIAutomationCacheRequest
$t:=new IUIAutomationTreeWalker

^6::
Loop 1
{

Element1 := $u.ElementFromPoint(65|99<<32)
V1 := $e.(Element1).CurrentName() . "`n"
V1 := Trim(V1, " `t`r`n") 
Element2 := $u.ElementFromPoint(382|134<<32)
V2 := $e.(Element2).CurrentValue() . "`n"
V2 := Trim(V2, " `t`r`n") 
Element3 := $u.ElementFromPoint(590|210<<32)
V3 := $e.(Element3).CurrentName() . "`n"
V3 := Trim(V3, " `t`r`n") 
Element4 := $u.ElementFromPoint(650|210<<32)
V4 := $e.(Element4).CurrentName() . "`n"
V4 := Trim(V4, " `t`r`n") 
Element5 := $u.ElementFromPoint(700|210<<32)
V5 := $e.(Element5).CurrentName() . "`n"
V5 := Trim(V5, " `t`r`n") 

MsgBox, % V1 " "V2 " " V3 " " V4 " " V5
}
return
Attachments
Screenshot_2022-08-13-10-17-47-78_6012fa4d4ddec268fc5c7112cbb265e7.jpg
Screenshot_2022-08-13-10-17-47-78_6012fa4d4ddec268fc5c7112cbb265e7.jpg (99.16 KiB) Viewed 1249 times

aifritz
Posts: 301
Joined: 29 Jul 2018, 11:30
Location: Germany

Re: AHK use UIA (inspect) get the text problem

Post by aifritz » 13 Aug 2022, 01:44

See example 1 in this thread
viewtopic.php?f=6&t=104999

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

Re: AHK use UIA (inspect) get the text problem  Topic is solved

Post by Descolada » 13 Aug 2022, 01:55

@Lo4438, you haven't said which UIA library you are using, so I can only give a general answer. To get the Value.Value with UIA you need to either
1) Use IUIAutomationElement.GetCurrentPropertyValue with UIA_ValueValuePropertyId
2) Use IUIAutomationElement.GetCurrentPattern with UIA_ValuePatternId and then access CurrentValue from ValuePattern

With the UIA_Interface.ahk you can do it easier:

Code: Select all

#Include UIA_Interface.ahk
UIA := UIA_Interface()
Element1 := UIA.ElementFromPoint(65, 99)
MsgBox, % Element1.Value

Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

Re: AHK use UIA (inspect) get the text problem

Post by Lo4438 » 13 Aug 2022, 04:30

Descolada, thank you so much.
:clap:
Sorry Bro, I have another Problem ( about FileAppend)
When I run the script, MsgBox can show the text,
But the ( FileAppend ) function doesn't work, s.txt file doesn't create.

Please help to solve this problem.

Code: Select all

#Include UIA_Interface.ahk
UIA := UIA_Interface()

^5::

Loop 1
{

Element1 := UIA.ElementFromPoint(40, 90)
V1 := Element1.Value
 
Element2 := UIA.ElementFromPoint(380, 120)
V2 := Element2.Value

Element3 := UIA.ElementFromPoint(492, 210)
V3 := Element3.Name
 
Element4 := UIA.ElementFromPoint(566, 210)
V4 := Element4.Name

Element5 := UIA.ElementFromPoint(606, 210)
V5 := Element5.Name


FileAppend, % V1 " "V2 " " V3 " " V4 " " V5, C:\Users\k\OneDrive\桌面\text file\s.txt
MsgBox, % V1 " "V2 " " V3 " " V4 " " V5
}
return
Attachments
Screenshot_2022-08-14-01-31-55-85_6012fa4d4ddec268fc5c7112cbb265e7.jpg
Screenshot_2022-08-14-01-31-55-85_6012fa4d4ddec268fc5c7112cbb265e7.jpg (41.35 KiB) Viewed 876 times

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

Re: AHK use UIA (inspect) get the text problem

Post by Descolada » 13 Aug 2022, 13:01

Make sure your target directory "text file" exists, and that your script is saved in UTF-8-BOM encoding. Other than that I don't know what the problem might be :?

Lo4438
Posts: 53
Joined: 18 May 2022, 10:00

Re: AHK use UIA (inspect) get the text problem

Post by Lo4438 » 13 Aug 2022, 13:12

Descolada, you are a genius.
:superhappy:

Post Reply

Return to “Ask for Help (v1)”