Page 1 of 1

AHK use UIA (inspect) get the text problem

Posted: 12 Aug 2022, 12:01
by Lo4438
Anybody can help me.

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

Please see the picture.

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

Posted: 12 Aug 2022, 15:48
by teadrinker
Try this:

Code: Select all

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

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

Posted: 12 Aug 2022, 21:56
by Lo4438
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

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

Posted: 13 Aug 2022, 01:44
by aifritz
See example 1 in this thread
viewtopic.php?f=6&t=104999

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

Posted: 13 Aug 2022, 01:55
by Descolada
@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

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

Posted: 13 Aug 2022, 04:30
by Lo4438
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

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

Posted: 13 Aug 2022, 13:01
by Descolada
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 :?

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

Posted: 13 Aug 2022, 13:12
by Lo4438
Descolada, you are a genius.
:superhappy: