Acc: get text from all window/control elements

Post your working scripts, libraries and tools for AHK v1.1 and older
potroveio
Posts: 8
Joined: 17 Sep 2019, 13:45

Re: Acc: get text from all window/control elements

27 Sep 2019, 12:17

Hi,

is this still working with Chrome 77?


I am trying to run this in order to have total tabs open on Chrome shown on a Message Box:

Code: Select all

JEE_ChromeGetTabCount(hWnd){
	oAcc := Acc_Get("Object", "4.1.2.1.1.1", 0, "ahk_id " hWnd)
	for _, oChild in Acc_Children(oAcc)
	{
		vTabText := oChild.accName(0)
		if !(vTabText == "")
		&& !(vTabText == "New Tab")
			vCount++
	}
	oAcc := oChild := ""
	return vCount
}


^+!a:: 
text1 = JEE_ChromeGetTabCount(hWnd)
MsgBox, %text1%
return

and get this errors:

>"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "C:\Users\martinhorst\atnbueno.ahk"
C:\Program Files\AutoHotkey\Lib\Acc.ahk (15) : ==> Duplicate function definition.
Specifically: Acc_Init()
>Exit code: 2 Time: 0.3308

I attach also the whole code, taken from another topic: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702

what am I doing wrong? please enlighten this newbie! Thanks!
Attachments
atnbueno.ahk
(6.52 KiB) Downloaded 108 times
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Acc: get text from all window/control elements

28 Sep 2019, 10:43

@potrovelo, I got the same error you did with Chrome 77. But it does work with mods as shown in the spoiler.

1) Chances are you already have Acc.ahk someplace the script found it (your LIB folder, most likely, where I myself have it); comment out all the "Acc_*" functions and the "Duplicate function definition" error will go a away. But more errors appear - not to worry, though.
2) As written, you are not grabbing the Hwnd of the browser window. Please try the code below, it works for me (you can comment out the MsgBox in the 'JEE_ChromeGetTabCount(hwnd)' hotkey section, of course).

Let me know if it doesn't work (I am at least getting a tab count, don't know if it's right). :D It won't get the right count if you add a tab after the script is running unless you reload.
Spoiler
Regards,
burque505
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Acc: get text from all window/control elements

29 Sep 2019, 20:09

@potroveio: I updated the Chrome functions, here:
Firefox/Chrome, get tab names/focus tab - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947&p=294316#p294316
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
unknownascaptain
Posts: 6
Joined: 23 Oct 2020, 14:59

Re: Acc: get text from all window/control elements

23 Oct 2020, 15:30

This is an amazing script, thank you so much for your dedication, jeeswg!
I'm still out of luck trying to access text inside a table of a certain program. Is it guaranteed that if JEE_AccGetTextAll cannot find the text I'm looking for, then no ACC code will?
Just to make sure, I looped through ALL the JEE_AccGetTextAll results from ALL open windows, and the only result I can find is my own text editor where I'm writing the script.
I set vLimN and vLimV to 99999 for the purposes of this test.

Code: Select all

q::
DetectHiddenWindows, On
WinGet windows, List
Loop %windows%
{
	id := windows%A_Index%
	WinGet, hWnd, ID, ahk_id %id%
	WinGetTitle wt, ahk_id %id%
	jee := JEE_AccGetTextAll(hWnd, "`r`n")
	if(InStr(jee, "A PIECE OF TEXT THAT I CAN SEE IN THE GOD-FORSAKEN WINDOW I'M TRYING TO FIND")){
		MsgBox, Found! in %wt% - %hWnd%
		MsgBox, % Clipboard := %jee%
	}
}
MsgBox, All done!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ntepa and 107 guests