AHK & Java Access Bridge

Get help with using AutoHotkey and its commands and hotkeys
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

AHK & Java Access Bridge

04 Jan 2019, 13:47

Dear Board Members,

I am pretty new to AHK and coming from my knowledge in VBA. I created some click and insert scripts now in AHK and some using / controlling excel via COM. Now I am getting stuck and really need help to find the path....

In the office our programs are emulated in Java GUI's. Of course Winspy, Winspector etc will not give me any controls or handles as they are not detected. After a lot of reading and learning (no Java knowledge at all!) I found some posts elated to java access brigde.

Under this link there is a ahk script written by Elgin:
https://autohotkey.com/board/topic/9534 ... /?p=601593

I have installed add. the java access bridge explorer which actually reads all the window informations in my Java Window. Nice!!!!

The script from Elgin above doesnt seem to work. When trying to start the JABTest.AHK it gives an error in line 2 and running the JControlWriter.ahk it says JAB not loaded. Although the explorer can read the window info's.

But still I am hang up and wouldnt know now how even to call any function in AHK directly to execute in my java window.
About any idea I would be greatful to get the track back.
tks..
Best regards
RinkaDink
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

04 Jan 2019, 14:13

Just to add it would be great if someone can just post a very simple code to access the menu in the java window.
Win title - on PHAM
in the tree view there is 5 panels and in the fifth there is menu bar
in the menu bar there are 6 menu items
i want to activate menu: BL ALT B --> menu item: mnemomic B
just as example.

Assume I need to write the code in a new ahk file and jjust add the functions from JavaAccessBridge.ahk, right ?
Elgin
Posts: 118
Joined: 30 Sep 2013, 09:19

Re: AHK & Java Access Bridge

04 Jan 2019, 16:09

Hi!

The most current code is here:
https://github.com/Elgin1/Java-Access-Bridge-for-AHK
I just tested it with Win10, Java 1.8.0_191 32 and 64 bit, AHK 1.1.30.01 64 bit and it works here.

The error messages you describe could occur if the Java access bridge is not enabled or AHK can't access the dll:
https://docs.oracle.com/javase/8/docs/t ... _test.html
If you have several versions of Java installed, they should all be enabled. Do you have the Java version installed that corresponds to the bittness of your AHK version? Don't know if that makes a difference but just to be sure...

Regarding your specific problem: If the menus can be accessed with key-presses as you write, I'd personally prefer that over using the JAB, as it's a lot easier. With the JAB you need to trigger the menu, then wait for and find the window that contains the menu and access the elements there.
If you want to use the JAB, then your code will look roughly like this when your window is active:

Code: Select all

JavaControlDoAction(0, "<INSERT NAME OF MENU HERE>", "menu", "", "1", "click")
Sleep, 100
JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", "click")

#Include JavaAccessBridge.ahk
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

04 Jan 2019, 16:51

wow, thanks Elgin. Getting your help is superb.
Will go on trying and follow your instructions.
I must confess I am still a super noob on AHK.

:D
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

04 Jan 2019, 17:28

Accessing the menu was trial to figure out the use in AHK in general. For the menu calling key-presses is working well.

Reasone why I would want to use JAB is this GUI has different screens that open from the main screen depending on the status of the dataset.
I came along and did imagesearch to lookup which screen is currently opened then process the next step based on that.
Actually though ending in the same issue as all once we intend to use the script on several machines you will need to recapture all images again due to
the different resolutions, dpi's etc. This would be an never ending approach.

Via JAB I could recognize the screen via the frame names and in some screens get the positions of controls for clicking i/o imagesearch

Java Version installed = 1.8.0_91 with 32 bit.
I activated Access Bridge via the control panel as described.
As I dont have any of these programs installed for testing and can not run installation as it is a corporate machine I couldnt run the test.
But it said as from Java 8 the JAB is already included and assume by activating it should be ok. Or can still something be missing ?

I exchanged the name in the sample code and tested. First Winactivate the Window and then nothing happens with the code lines above.
I also put settitlemode = 2 to be sure that it doesnt just ignore due to spelling...
Elgin
Posts: 118
Joined: 30 Sep 2013, 09:19

Re: AHK & Java Access Bridge

04 Jan 2019, 18:40

Did you try the 32 bit unicode version of AHK since you only have 32bit Java?

For me my code starts/stops working in the same situations as the java access bridge explorer. I only did a few tests, though...

Otherwise you could try to insert a few Msgbox commands into InitJavaAccessBridge() in the code after the "if" to figure out what happens and where the dll calls start to go wrong.
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

05 Jan 2019, 11:05

Dear Elgin,

yes I am using 32 bit AHK. I tested now on a second computer. Here JAB and AHK is working fine. This computer though is my private and doesnt have the office work environment softwares. I suspect that I found the error cause. And unfortunately it is a very basic on the installation.

The system I need to have the JAB is running on a virtual machine on a citrix environment. JRE is installed in vers. 1.8.0_91 but not JDK.
in Win/Sys32 the JAB.DLL's are not existant and I cant put them in there as you need admin rights.

Best regards
Rinkadink
Last edited by RinkaDink on 05 Jan 2019, 15:30, edited 1 time in total.
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

05 Jan 2019, 15:21

I will ask my admin to install what I need correctly.
If you allow me one more question towards function.

The program has various internal frames which I want to check by the name on which is currently active.
Example: One is called Overview

How do I check if internal frame "Overview" is active ?

Best regards
Rinkadink
Elgin
Posts: 118
Joined: 30 Sep 2013, 09:19

Re: AHK & Java Access Bridge

05 Jan 2019, 18:27

The dlls are installed as part of the JRE, not the JDK; looks like someone took a shortcut when preparing that VM ;-)

To check which frame is active you have several options depending on how often you need to do it:

a) call GetAccessibleContextWithFocus() to get the current focused control at that moment
b) track focus events with setFocusGainedFP(fp) to be notified every time the focus changes (see comment in JavaAccessBridge.ahk on how to handle events).

From there it depends on how your application is structured. A frame will usually not have focus itself, i.e. have the "focused" state (see GetAccessibleContextInfo), but rather some control inside it, so you will probably have to use GetParentWithRole() to get to the relevant frame and read out it's name to figure out where you are.
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

05 Jan 2019, 20:08

Hello Elgin,
so you will probably have to use GetParentWithRole() to get to the relevant frame and read out it's name to figure out where you are.
That a frame will not be focused is understood and I follow but now it gets messy in my understanding.

Could you give an example based on the SwingSet2 Demo ?
There is a textbox in the right side. The object depth is 15. In Object depth 9 the parent window role name is "desktop pane".

Would it be possible to check if specific textbox is visible ?
Or will it only be possible to check what is the current focused control (as textbox will not be focused when opening) ?
If I got the current focused control of each screen how would I read all parent names and check if one of those names is equal to "desktop pane" ?

Best regards
RinkaDink
Elgin
Posts: 118
Joined: 30 Sep 2013, 09:19

Re: AHK & Java Access Bridge

06 Jan 2019, 04:41

Would it be possible to check if specific textbox is visible ?
See code below. Press F10.
Or will it only be possible to check what is the current focused control (as textbox will not be focused when opening) ?
Press F12 to get the current focused control.
If I got the current focused control of each screen how would I read all parent names and check if one of those names is equal to "desktop pane" ?
I'm not sure I understand you correctly. There is only one focused control at any time and hence only one parent frame. Have a look at the code under F11 to see if it does what you want.

Code: Select all

InitJavaAccessBridge()
return

#Include JavaAccessBridge.ahk

F10::
	vmID:=0
	ac:=0
	IFrame:=JavaControlGet(0, "Internal Frame Generator", "internal frame")
	If (IsObject(IFrame))
	{
		ChildTextBox:=JavaControlGet(0, "", "text", "", "", IFrame)
		if (ChildTextBox.ac<>0)
		{
			MsgBox, % "The textbox is visible."
		}
		else
		{
			MsgBox, % "The textbox is not visible."
		}
	}
	else
	{
		MsgBox, % "The internal frame and the textbox are not visible."
	}
return

F11::
	vmID:=0
	ac:=0
	GetAccessibleContextWithFocus(WinExist("A"),vmID,ac)
	parentrole:="internal frame"
	acparent:=GetParentWithRole(vmID, ac, parentrole)
	if (acparent<>0)
	{
		Info:=GetAccessibleContextInfo(vmID,acparent)
		MsgBox, % "Currently focused internal frame: Name """ Info.Name """; Role: """ Info.Role """; States: """ Info.States """"
	}
	else
	{
		MsgBox, % "None of the internal frames is currently focused."
	}
return

F12::
	vmID:=0
	ac:=0
	GetAccessibleContextWithFocus(WinExist("A"),vmID,ac)
	Info:=GetAccessibleContextInfo(vmID,ac)
	ToolTip, % "Currently focused: Name """ Info.Name """; Role: """ Info.Role """; States: """ Info.States """"
return
RinkaDink
Posts: 30
Joined: 03 Sep 2018, 14:52
Facebook: 1982
Google: 1982

Re: AHK & Java Access Bridge

06 Jan 2019, 08:15

Hello Elgin,

tested and F10 lookup may already be sufficent to achieve what I need.
I will have to test on my company machine once java is setup correctly but tests with Swingset were good.
Your code is awsome and I am really greatful that you made this.

Thanks!

Best regards
RnkaDink
netaware
Posts: 12
Joined: 29 Apr 2015, 12:52

Re: AHK & Java Access Bridge

23 Sep 2019, 13:08

Hello, I am trying to use JAB.
I have enabled the jab view, but when i run the JAB AHK i get en error saying:
"Error in line 141."

Can you please give me any help with this?
Elgin
Posts: 118
Joined: 30 Sep 2013, 09:19

Re: AHK & Java Access Bridge

24 Sep 2019, 10:24

Hi netaware,

sorry but your description is a bit too vague to say anything...
Which file exactly did you run and what error did you get? Also helpful would be the AHK version 32/64bit and the installed JRE also 32/64bit.

Regards,

Elgin
allinall8
Posts: 1
Joined: 29 Feb 2020, 04:28

Re: AHK & Java Access Bridge

29 Feb 2020, 05:22

Elgin wrote: Hi!

The most current code is here:
https://github.com/Elgin1/Java-Access-Bridge-for-AHK
I just tested it with Win10, Java 1.8.0_191 32 and 64 bit, AHK 1.1.30.01 64 bit and it works here.

The error messages you describe could occur if the Java access bridge is not enabled or AHK can't access the dll:
https docs.oracle.com /javase/8/docs/technotes/guides/access/enable_and_test.html Broken Link for safety
If you have several versions of Java installed, they should all be enabled. Do you have the Java version installed that corresponds to the bittness of your AHK version? Don't know if that makes a difference but just to be sure...

Regarding your specific problem: If the menus can be accessed with key-presses as you write, I'd personally prefer that over using the JAB, as it's a lot easier. With the JAB you need to trigger the menu, then wait for and find the window that contains the menu and access the elements there.
If you want to use the JAB, then your code will look roughly like this when your window is active:

Code: Select all

JavaControlDoAction(0, "<INSERT NAME OF MENU HERE>", "menu", "", "1", "click")
Sleep, 100
JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", "click")

#Include JavaAccessBridge.ahk
Hi, I'm pretty new at this and just have a quick question about how you would setTextcontent/ enter text and/or get text values back. So i can see that you've mentioned the code should looks something like that for clicks but how would the code look like for entering or getting text/string? is it something simple like the below or is it alot different? I've looked through some of the other post relating to JAB but couldn't see if this was an option.

Code: Select all

JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", setTextContent = "Hello")

#Include JavaAccessBridge.ahk
Apologies if i've asked this in a strange way.
snowmind
Posts: 124
Joined: 12 Nov 2015, 15:18

Re: AHK & Java Access Bridge

31 Aug 2020, 10:27

allinall8 wrote:
29 Feb 2020, 05:22
Elgin wrote: Hi!

The most current code is here:
https://github.com/Elgin1/Java-Access-Bridge-for-AHK
I just tested it with Win10, Java 1.8.0_191 32 and 64 bit, AHK 1.1.30.01 64 bit and it works here.

The error messages you describe could occur if the Java access bridge is not enabled or AHK can't access the dll:
https docs.oracle.com /javase/8/docs/technotes/guides/access/enable_and_test.html Broken Link for safety
If you have several versions of Java installed, they should all be enabled. Do you have the Java version installed that corresponds to the bittness of your AHK version? Don't know if that makes a difference but just to be sure...

Regarding your specific problem: If the menus can be accessed with key-presses as you write, I'd personally prefer that over using the JAB, as it's a lot easier. With the JAB you need to trigger the menu, then wait for and find the window that contains the menu and access the elements there.
If you want to use the JAB, then your code will look roughly like this when your window is active:

Code: Select all

JavaControlDoAction(0, "<INSERT NAME OF MENU HERE>", "menu", "", "1", "click")
Sleep, 100
JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", "click")

#Include JavaAccessBridge.ahk
Hi, I'm pretty new at this and just have a quick question about how you would setTextcontent/ enter text and/or get text values back. So i can see that you've mentioned the code should looks something like that for clicks but how would the code look like for entering or getting text/string? is it something simple like the below or is it alot different? I've looked through some of the other post relating to JAB but couldn't see if this was an option.

Code: Select all

JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", setTextContent = "Hello")

#Include JavaAccessBridge.ahk
Apologies if i've asked this in a strange way.
I would like to know this too
unfortunately no one answered :(

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, hasantr, just me, mikeyww, username123, WilliamJ, Xeo786 and 47 guests