Page 1 of 1

set value to Acc object children?

Posted: 07 Aug 2017, 00:05
by joshatt
Hi all,
A text box in some window is my target. The following code pops up the correct message text, meaning Acc part is correct.

Code: Select all

#SingleInstance force
#include Acc.ahk

WinGet,hWnd,id, SOMETITLE
window := Acc_ObjectFromWindow(hWnd) 
children := Acc_Children(window) 
MsgBox % children[11].accValue(0) 
But then, I added one more line: acc.children[11].accValue(0) := "new.mp4" (or: children[11].accValue(0) := "new.mp4")
Nothing happened.
How can I set a new value?

Thanks.

Re: set value to Acc object children?

Posted: 08 Aug 2017, 21:41
by joshatt
Or, is it possible to focus on this text box object?

Re: set value to Acc object children?

Posted: 09 Aug 2017, 04:28
by Elgin
Hi!

Depending on the type of edit-control, accValue is most likely implemented as read-only. There's no "set_accValue" defined:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

You can (usually...) set the focus to the control by calling "accSelect" with the flag SELFLAG_TAKEFOCUS (0x1):
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

Untested:

Code: Select all

children[11].accSelect(0x1,0)
Then you can use SendInput or whatever you like to set the new text.

Re: set value to Acc object children?

Posted: 09 Aug 2017, 05:09
by joshatt
Elgin wrote:Hi!

Depending on the type of edit-control, accValue is most likely implemented as read-only. There's no "set_accValue" defined:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

You can (usually...) set the focus to the control by calling "accSelect" with the flag SELFLAG_TAKEFOCUS (0x1):
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

Untested:

Code: Select all

children[11].accSelect(0x1,0)
Then you can use SendInput or whatever you like to set the new text.
Thanks for your help.
Today somebody told me, and I found out the full path of this object should be "4,11",instead. So, how am I supposed to write this line "children[11].accSelect(0x1,0)" ?

Re: set value to Acc object children?

Posted: 09 Aug 2017, 05:54
by Elgin
"Path", "4, 11"? Is that something specific to "acc.ahk" (which I don't use)?

If it refers to the position in the tree: Root -> Child no. 4 -> Child no. 11 then your code would probably have to look like this:

Code: Select all

#SingleInstance force
#include Acc.ahk

WinGet,hWnd,id, SOMETITLE
window := Acc_ObjectFromWindow(hWnd) 
children := Acc_Children(window) 
grandchildren := Acc_Children(children[4])
grandchildren[11].accSelect(0x1,0)
MsgBox % grandchildren[11].accValue(0) 
Again untested.

Re: set value to Acc object children?

Posted: 09 Aug 2017, 06:28
by jeeswg
This might work:

Code: Select all

oAcc := Acc_Get("Object", "4.11", 0, "ahk_id " hWnd)

Re: set value to Acc object children?

Posted: 09 Aug 2017, 18:07
by joshatt
Elgin wrote:"Path", "4, 11"? Is that something specific to "acc.ahk" (which I don't use)?

Code: Select all

#SingleInstance force
#include Acc.ahk

WinGet,hWnd,id, SOMETITLE
window := Acc_ObjectFromWindow(hWnd) 
children := Acc_Children(window) 
grandchildren := Acc_Children(children[4])
grandchildren[11].accSelect(0x1,0)
MsgBox % grandchildren[11].accValue(0) 
Again untested.
This one returns empty value.

As for the path, both the following codes work, but then the accSelect(0x1,0) part still not working.

Code: Select all

WinGet,hWnd,id, SOMETITLE
window := Acc_ObjectFromWindow(hWnd) 
children := Acc_Children(window) 
Msgbox, % children[11].accValue(0) 

Code: Select all

acc := Acc_Get("Object", "4,11", 0, "SOMETITLE")
MsgBox, % acc.accValue(0)

Re: set value to Acc object children?

Posted: 10 Aug 2017, 01:46
by Elgin
Hi again.

This bugged me, so I downloaded acc.ahk from here (so we're sure we're talking about the same thing...):
https://github.com/Drugoy/Autohotkey-sc ... es/Acc.ahk

On a freshly started Win10 File Explorer instance (to make sure the window title is "File Explorer") this code:

Code: Select all

#SingleInstance force
#include Acc.ahk

WinGet,hWnd,id, File Explorer
oAcc := Acc_Get("Object", "4.5.4.1.4.9.4.1.4.1.4.1.4.1", 0, "ahk_id " hWnd) ; selects the Search Quick Access edit field
MsgBox % Acc_Role(oAcc) "; " Acc_State(oAcc) ; should read "editable text; focusable" if the above went well
WinActivate, File Explorer
oAcc.accSelect(0x1,0)
SendInput, New.mp3
Sleep, 100
MsgBox, % oAcc.accValue(0) ; should read "New.mp3"
puts the focus in the Search Quick Access edit field, enters new text and displays the new value.

Have you confirmed the path to the control you want in AccViewer?

Re: set value to Acc object children?

Posted: 10 Aug 2017, 05:09
by tmplinshi
For others who want to test this, the program he mentioned was flareget.

Image

Code: Select all

acc := acc_get("Object", "4.11", 0, "New Download")
MsgBox, % Acc_GetRoleText( acc.accRole(0) )
MsgBox, % acc.accValue(0) ; works
acc.accValue(0) := "New Value" ; failed
Not sure if this is a bug in Acc.ahk, or just that element doesn't support setting values.

Anyway here is a working code using "set focus" and "ControlSend":

Code: Select all

acc := acc_get("Object", "4.11", 0, "New Download")
acc.accDoDefaultAction(0) ; Set Focus
ControlSend,, ^a ; Select All
ControlSendRaw,, New_Value_Here

Re: set value to Acc object children?

Posted: 10 Aug 2017, 08:52
by tank

Re: set value to Acc object children?

Posted: 11 Aug 2017, 16:58
by joshatt
Elgin wrote:Hi again.

This bugged me, so I downloaded acc.ahk from here (so we're sure we're talking about the same thing...):
https://github.com/Drugoy/Autohotkey-sc ... es/Acc.ahk

On a freshly started Win10 File Explorer instance (to make sure the window title is "File Explorer") this code:

Code: Select all

#SingleInstance force
#include Acc.ahk

WinGet,hWnd,id, File Explorer
oAcc := Acc_Get("Object", "4.5.4.1.4.9.4.1.4.1.4.1.4.1", 0, "ahk_id " hWnd) ; selects the Search Quick Access edit field
MsgBox % Acc_Role(oAcc) "; " Acc_State(oAcc) ; should read "editable text; focusable" if the above went well
WinActivate, File Explorer
oAcc.accSelect(0x1,0)
SendInput, New.mp3
Sleep, 100
MsgBox, % oAcc.accValue(0) ; should read "New.mp3"
puts the focus in the Search Quick Access edit field, enters new text and displays the new value.

Have you confirmed the path to the control you want in AccViewer?
Thanks again and sorry for the delay, I did not get thread update email notification the last two days.
Just tried your code with this flareget software, it set focus on another edit field "URL"(as shown in tmplinshi's picture), sent "new.mp3", and the last msgbox read empty value.
Seems this software is a little weird. And tmplinshi's method proved fine. Also someone else told me a method, with Acc_Get("Location"...)...controlclick..., which proved fine.

Re: set value to Acc object children?

Posted: 11 Aug 2017, 17:03
by joshatt
tmplinshi wrote: Not sure if this is a bug in Acc.ahk, or just that element doesn't support setting values.

Anyway here is a working code using "set focus" and "ControlSend":

Code: Select all

acc := acc_get("Object", "4.11", 0, "New Download")
acc.accDoDefaultAction(0) ; Set Focus
ControlSend,, ^a ; Select All
ControlSendRaw,, New_Value_Here
Perfect and simple!
I did noticed this as in the following picture, thinking maybe I could do something, this is it!
acc3.png
acc3.png (21 KiB) Viewed 2359 times
Thank you for your help!

Re: set value to Acc object children?  Topic is solved

Posted: 09 Nov 2018, 16:50
by DRocks
I've been struggling to get this to work for about a year. Was discouraged and gave up. But I tried now with more knowledge and intuition using AHK to finally get a result.

Code: Select all

	!q:: ; acc viewer / acc.ahk test
	CumulNN:= "WindowsForms10.Window.8.app.0." SageWinClassPattern "_r38_ad17"
	ControlGet,hCtl, HWND,, %CumulNN%, Chèques de paie
		 ;Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")
	oAcc:= acc_get("Object", "4.2.6", 0, "ahk_id " hCtl)
	MsgBox, % oAcc.accValue(0)
	return
This is able to get a precise value that is not seen by Window Spy.

I need to:

1. get the Control's Hwnd[/b ] using its ClassNN 1st.
2. get the path of that control with Acc Viewer wihich reveals 2.6 when focusing the cross directly onto the wanted control... 2.6 is not enough because it is relative to another container for this control.
3. get the path of the container above the control's path which is 4
4. sum it up to 4.2.6 as the childPath and it will find the value

Thanks to JeeSwg

Re: set value to Acc object children?

Posted: 23 Dec 2018, 19:14
by joshatt
DRocks wrote:
09 Nov 2018, 16:50
I've been struggling to get this to work for about a year. Was discouraged and gave up. But I tried now with more knowledge and intuition using AHK to finally get a result.

Code: Select all

	!q:: ; acc viewer / acc.ahk test
	CumulNN:= "WindowsForms10.Window.8.app.0." SageWinClassPattern "_r38_ad17"
	ControlGet,hCtl, HWND,, %CumulNN%, Chèques de paie
		 ;Acc_Get(Cmd, ChildPath="", ChildID=0, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")
	oAcc:= acc_get("Object", "4.2.6", 0, "ahk_id " hCtl)
	MsgBox, % oAcc.accValue(0)
	return
This is able to get a precise value that is not seen by Window Spy.

I need to:

1. get the Control's Hwnd[/b ] using its ClassNN 1st.
2. get the path of that control with Acc Viewer wihich reveals 2.6 when focusing the cross directly onto the wanted control... 2.6 is not enough because it is relative to another container for this control.
3. get the path of the container above the control's path which is 4
4. sum it up to 4.2.6 as the childPath and it will find the value

Thanks to JeeSwg


Thanks for your help, and sorry, haven't been back for a long time. I'll try with your code.