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
AHK & Java Access Bridge
Re: AHK & Java Access Bridge
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 ?
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 ?
Re: AHK & Java Access Bridge
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:
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
Re: AHK & Java Access Bridge
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.
Will go on trying and follow your instructions.
I must confess I am still a super noob on AHK.
Re: AHK & Java Access Bridge
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...
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...
Re: AHK & Java Access Bridge
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.
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.
Re: AHK & Java Access Bridge
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
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.
Re: AHK & Java Access Bridge
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
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
Re: AHK & Java Access Bridge
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.
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.
Re: AHK & Java Access Bridge
Hello Elgin,
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
That a frame will not be focused is understood and I follow but now it gets messy in my understanding.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.
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
Re: AHK & Java Access Bridge
See code below. Press F10.Would it be possible to check if specific textbox is visible ?
Press F12 to get the current focused control.Or will it only be possible to check what is the current focused control (as textbox will not be focused when opening) ?
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.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" ?
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
Re: AHK & Java Access Bridge
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
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
Re: AHK & Java Access Bridge
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?
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?
Re: AHK & Java Access Bridge
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
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
Re: AHK & Java Access Bridge
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.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
Code: Select all
JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", setTextContent = "Hello")
#Include JavaAccessBridge.ahk
Re: AHK & Java Access Bridge
I would like to know this tooallinall8 wrote: ↑29 Feb 2020, 05:22Hi, 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.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
Apologies if i've asked this in a strange way.Code: Select all
JavaControlDoAction(0, "<INSERT NAME OF MENU ITEM HERE>", "<INSERT TYPE OF MENU ITEM HERE>", "", "1", setTextContent = "Hello") #Include JavaAccessBridge.ahk
unfortunately no one answered
Re: AHK & Java Access Bridge
Thank you so much! I test it with swingset3 and it works! However, I cannot make it work with IntelliJ IDEA, e.g., click the File menu:
Code:
Could you help me out, thanks!
Code:
Code: Select all
SetTitleMatchMode, 2
WinActivate, IntelliJ IDEA
sleep, 2000
JavaControlDoAction(0, "File", "menu", "", "1", "left click")
msgbox, Done!
return
#Include JavaAccessBridge.ahk
Re: AHK & Java Access Bridge
You probably should have a try shouting out @Elgin and/or to check if (s)he's available at the Discord Server. Good luck
Re: AHK & Java Access Bridge
Hi pythonker,
I just tried it and for me this code works:
Have you checked with JControlWriter.ahk if the accessibility is working properly in IntelliJ and that you see all the elements? If not you might have to run "jabswitch.exe /enable" from your JRE /bin folder again and restart IntelliJ to get it going.
I just tried it and for me this code works:
Code: Select all
F11::
if !InitJavaAccessBridge()
{
msgbox, JAB not loaded!
}
rval:=JavaControlDoAction(0, "Search Everywhere", "push button", "", "1", "left click")
return
F12::
if !InitJavaAccessBridge()
{
msgbox, JAB not loaded!
}
rval:=JavaControlDoAction(0, "File", "menu", "", "1", "left click")
return
#Include JavaAccessBridge.ahk
Re: AHK & Java Access Bridge
Thanks for your reply!
I tried this code and F12 worked and F11 failed, then I found the reason why my code failed is that, the window of IDEA is not full-screen-sized, and the window is moved from the top-left corner of the screen to the right-half of screen.
Another problem related is using ^!F10 in JControlWriter.ahk to show the list of all visible controls will only show a green-bordered box smaller than the window of IDEA, and if I move IDEA to right-half of screen, ^!F10 still shows green box at the top-left position.
So, using F12 to click File menu works because the window starts at the top-left corner, if I move IDEA to right-half of screen, both F11 and F12 cannot work.
I tried this code and F12 worked and F11 failed, then I found the reason why my code failed is that, the window of IDEA is not full-screen-sized, and the window is moved from the top-left corner of the screen to the right-half of screen.
Another problem related is using ^!F10 in JControlWriter.ahk to show the list of all visible controls will only show a green-bordered box smaller than the window of IDEA, and if I move IDEA to right-half of screen, ^!F10 still shows green box at the top-left position.
So, using F12 to click File menu works because the window starts at the top-left corner, if I move IDEA to right-half of screen, both F11 and F12 cannot work.
- Attachments
-
- green-box-smaller-than-window.jpg (118.45 KiB) Viewed 5607 times
Who is online
Users browsing this forum: No registered users and 121 guests