B4J Library jAutoItX Library

jmon

Well-Known Member
Licensed User
Hello,

About AutoIt and AutoIt4Java:
AutoIt is a very useful automation scripting language for Microsoft Windows. It allows for GUI automation using a very simple syntax and can be useful for testing Windows applications. It is packaged with AutoItX which supports accessing AutoIt functions through COM objects.
AutoItX4Java uses JACOB to access AutoItX through COM and strives to provide a native Java interface while maintaining the simplicity of AutoIt. Getting started is simple.

How to use this library?:
  1. Copy To external libraries:
    • AutoItX4Java.jar
    • jAutoItX.jar
    • jAutoItX.xml
  2. Copy to your project /Objects/Lib:
    • jacob.dll
    • AutoitX.dll
  3. Register AutoitX.dll with this function (Depends on jShell)
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    'Register autoitX DLL First:
    RegisterAutoItX

    'Initialize jAutoItX:
    AutoItX.Initialize

    '....
End Sub

Private Sub RegisterAutoItX As Boolean
    Dim sh As Shell
    sh.Initialize("", "regsvr32.exe", Array("/s", $""${File.Combine(File.DirApp, "/lib/AutoItX3.dll")}""$))
    Dim Result As ShellSyncResult = sh.RunSynchronous(2000)
    Return Result.Success
End Sub
*For Java 64 bit, please read the notes below.*

143 Methods and 26 Constants:

1 public static final int SW_MAXIMIZE
2 public static final int SW_HIDE
3 public static final int SW_RESTORE
4 public static final int SW_SHOW
5 public static final int SW_SHOWDEFAULT
6 public static final int SW_SHOWMAXIMIZED
7 public static final int SW_SHOWMINIMIZED
8 public static final int SW_SHOWMINNOACTIVE
9 public static final int SW_SHOWNA
10 public static final int SW_SHOWNOACTIVATE
11 public static final int SW_SHOWNORMAL
12 public static final String OPT_CARET_COORD_MODE
13 public static final String OPT_MOUSE_CLICK_DELAY
14 public static final String OPT_MOUSE_CLICK_DOWN_DELAY
15 public static final String OPT_MOUSE_CLICK_DRAG_DELAY
16 public static final String OPT_MOUSE_COORD_MODE
17 public static final String OPT_PIXEL_COORD_MODE
18 public static final String OPT_SEND_ATTACH_MODE
19 public static final String OPT_SEND_CAPSLOCK_MODE
20 public static final String OPT_SEND_KEY_DELAY
21 public static final String OPT_SEND_KEY_DOWN_DELAY
22 public static final String OPT_WIN_DETECT_HIDDEN_TEXT
23 public static final String OPT_WIN_SEARCH_CHILDREN
24 public static final String OPT_WIN_TEXT_MATCH_MODE
25 public static final String OPT_WIN_TITLE_MATCH_MODE
26 public static final String OPT_WIN_WAIT_DELAY
27 public int getError()
28 public String clipGet()
29 public void clipPut(String value)
30 public boolean driveMapAdd(String device, String remote, int flags, String username, String password)
31 public boolean driveMapDelete(String device)
32 public String driveMapGet(String device)
33 public boolean iniDelete(String filename, String section, String key)
34 public String iniRead(String filename, String section, String key, String defaultVal)
35 public Boolean iniWrite(String filename, String section, String key, String value)
36 public double pixelChecksum(int left, int top, int right, int bottom, int step)
37 public float pixelGetColor(int x, int y)
38 public long[] pixelSearch(int left, int top, int right, int bottom, int color, int shadeVariation, int step)
39 public void send(String keys, boolean isRaw)
40 public void toolTip(String text, int x, int y)
41 public void blockInput(boolean disableInput)
42 public boolean cdTray(String drive, String status)
43 public boolean isAdmin()
44 public String autoItSetOption(String option, String param)
45 public String setOption(String option, String param)
46 public void mouseClick(String button, int x, int y, int clicks, int speed)
47 public void mouseClickDrag(String button, int x, int y, int x2, int y2, int speed)
48 public void mouseDown(String button)
49 public int mouseGetCursor()
50 public int mouseGetPosX()
51 public int mouseGetPosY()
52 public boolean mouseMove(int x, int y, int speed)
53 public void mouseUp(String button)
54 public void mouseWheel(String direction, int clicks)
55 public void processClose(String process)
56 public int processExists(String process)
57 public boolean processSetPriority(String process, int priority)
58 public boolean processWait(String process, int timeout)
59 public boolean processWaitClose(String process, int timeout)
60 public int run(String filename, String workingDirectory, int flag)
61 public int runAsSet(String username, String domain, String password, int options)
62 public int runWait(String filename, String workingDirectory, int flag)
63 public boolean shutdown(int code)
64 public int regDeleteKey(String keyname)
65 public int regDeleteVal(String keyname)
66 public String regEnumKey(String keyname, int instance)
67 public String regEnumVal(String keyname, int instance)
68 public String regRead(String keyname, String valueName)
69 public boolean regWrite(String keyname, String valueName, String type, String value)
70 public void sleep(int delay)
71 public boolean controlClick(String title, String text, String controlID, String button, int clicks, int x, int y)
72 public void controlCommandShowDropdown(String title, String text, String control)
73 public void controlCommandHideDropDown(String title, String text, String control)
74 public void controlCommandCheck(String title, String text, String control)
75 public void controlCommandUncheck(String title, String text, String control)
76 public void controlCommandAddString(String title, String text, String control, String string)
77 public void controlCommandDeleteString(String title, String text, String control, String occurance)
78 public void controlCommandEditPaste(String title, String text, String control, String string)
79 public void controlCommandSetCurrentSelection(String title, String text, String control, String occurance)
80 public void controlCommandSelectString(String title, String text, String control, String string)
81 public boolean controlCommandIsVisible(String title, String text, String control)
82 public boolean controlCommandIsChecked(String title, String text, String control)
83 public boolean controlCommandIsEnabled(String title, String text, String control)
84 public int controlCommandFindString(String title, String text, String control, String string)
85 public int controlCommandGetCurrentLine(String title, String text, String control)
86 public int controlCommandGetCurrentCol(String title, String text, String control)
87 public int controlCommandGetLineCount(String title, String text, String control)
88 public String controlCommandGetCurrentSelection(String title, String text, String control, int charLength)
89 public String controlCommandGetSelected(String title, String text, String control, int charLength)
90 public void controlCommandTabLeft(String title, String text, String control)
91 public void controlCommandTabRight(String title, String text, String control)
92 public String controlCommandCurrentTab(String title, String text, String control)
93 public boolean controlDisable(String title, String text, String control)
94 public boolean controlEnable(String title, String text, String control)
95 public boolean controlFocus(String title, String text, String control)
96 public String controlGetFocus(String title, String text)
97 public String controlGetHandle(String title, String text, String controlID)
98 public int controlGetPosX(String title, String text, String controlID)
99 public int controlGetPosY(String title, String text, String controlID)
100 public int controlGetPosWidth(String title, String text, String controlID)
101 public int controlGetPosHeight(String title, String text, String controlID)
102 public String controlGetText(String title, String text, String controlID)
103 public boolean controlHide(String title, String text, String controlID)
104 public int controlListViewFindItem(String title, String text, String control, String string, String subitem)
105 public int controlListViewGetItemCount(String title, String text, String control)
106 public int controlListViewGetSelectedCount(String title, String text, String control)
107 public int controlListViewGetSubItemCount(String title, String text, String control)
108 public String controlListViewGetText(String title, String text, String control, String item, String subitem)
109 public boolean controlListViewIsSelected(String title, String text, String control, String item)
110 public String controlListViewGetSelected(String title, String text, String control)
111 public String[] controlListViewGetSelectedArray(String title, String text, String control)
112 public void controlListViewSelect(String title, String text, String control, String from, String to)
113 public void controlListViewSelectAll(String title, String text, String control, String from, String to)
114 public void controlListViewSelectClear(String title, String text, String control)
115 public void controlListViewSelectInvert(String title, String text, String control)
116 public void controlListViewSelectViewChange(String title, String text, String control, String view)
117 public boolean controlMove(String title, String text, String control, int x, int y, int width, int height)
118 public boolean controlSend(String title, String text, String control, String string, boolean sendRawKeys)
119 public boolean ControlSetText(String title, String text, String control, String string)
120 public boolean controlShow(String title, String text, String control)
121 public boolean controlTreeViewBoolean(String title, String text, String control, String command, String option, String option2)
122 public void controlTreeViewCheck(String title, String text, String control, String item)
123 public void controlTreeViewCollapse(String title, String text, String control, String item)
124 public Boolean controlTreeViewExists(String title, String text, String control, String item)
125 public void controlTreeViewExpand(String title, String text, String control, String item)
126 public int controlTreeViewGetItemCount(String title, String text, String control, String item)
127 public int controlTreeViewGetSelectedItemIndex(String title, String text, String control)
128 public String controlTreeViewGetSelectedItemText(String title, String text, String control)
129 public String controlTreeViewGetText(String title, String text, String control, String item)
130 public int controlTreeViewIsChecked(String title, String text, String control)
131 public void controlTreeViewSelect(String title, String text, String control, String item)
132 public void controlTreeViewUncheck(String title, String text, String control, String item)
133 public String statusbarGetText(String title, String text, int part)
134 public void winActivate(String title, String text)
135 public void winActive(String title, String text)
136 public void winClose(String title, String text)
137 public boolean winExists(String title, String text)
138 public int winGetCaretPosX()
139 public int winGetCaretPosY()
140 public String winGetClassList(String title, String text)
141 public int winGetClientSizeWidth(String title, String text)
142 public int winGetClientSizeHeight(String title, String text)
143 public String winGetHandle(String title, String text)
144 public int winGetPosX(String title, String text)
145 public int winGetPosY(String title, String text)
146 public int winGetPosWidth(String title, String text)
147 public int winGetPosHeight(String title, String text)
148 public String winGetProcess(String title, String text)
149 public int winGetState(String title, String text)
150 public String winGetText(String title, String text)
151 public String winGetTitle(String title, String text)
152 public void winKill(String title, String text)
153 public String[][] winList(String title, String text)
154 public boolean winMenuSelectItem(String title, String text, String item, String item2, String item3, String item4, String item5, String item6, String item7)
155 public void winMinimizeAll()
156 public void winMinimizeAllUndo()
157 public void winMove(String title, String text, int x, int y, int width, int height)
158 public void winSetOnTop(String title, String text, boolean isTopMost)
159 public void winSetState(String title, String text, int flag)
160 public void winSetTitle(String title, String text, String newtitle)
161 public boolean winSetTrans(String title, String text, int transparency)
162 public boolean winWait(String title, String text, int timeout)
163 public boolean winWaitActive(String title, String text, int timeout)
164 public boolean winWaitClose(String title, String text, int timeout)
165 public boolean winWaitNoActive(String title, String text, int timeout)
Licenses (AutoIt, JACOB, Richard Kanavati) -> Please Read:
AutoIt License:
JACOB License:
JACOB is under the license:
GNU Library General Public License, version 2.0
http://www.gnu.org/licenses/old-licenses/lgpl-2.0.en.html
The code of this library is based on the work done by Richard Kanavati. (Big thanks to him :))
License:
/**
* Copyright (c) 2011 Richard Kanavati
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

Notes:
  • This won't work on Linux, Mac OS, B4A, B4I and B4R.
  • You can run the register function every time you start your program, it's safe.
  • The jacob version included in this post is the version 1.18 (x86).
  • For Java 64 bit, download jacob-x.xx-x64.dll (Click HERE), rename it to jacob.dll and replace the old dll.
 

Attachments

Last edited:

jmon

Well-Known Member
Licensed User
I think I will be useful.
I think it is. Just a pity that the win... functions don't work. AutoIt is great for automation and it also allows B4J to know more about things going on outside the javafx window, like the processes and windows etc... I am still trying to make the win function to work properly.
 
Last edited:

Theera

Well-Known Member
Licensed User
Thank you,jmon I've done. But I don't know BuildJavaLibrary.au3 file which attached how is used for create your library.
 
Last edited:

jmon

Well-Known Member
Licensed User
Thank you,jmon I've done. But I don't know BuildJavaLibrary.au3 file which attached how is used for create your library.
Do the "winxxxxx" and "controlxxxx" work for you?

About the BuildJavaLibrary.au3, it's an AutoIt file. You need to install autoit and Scite for Autoit, then in scite, press F5 to execute it. But this conversion of webpage to java script could easily have been done with B4J.

[edit] clarified second paragraph.
 
Last edited:

jmon

Well-Known Member
Licensed User
So.. I have been trying to make the functions "winxxx" and "controlxxxx" work, but no luck so far.

I hope that someone with more knowledge in java will be able to figure where the problems come from.
 

agraham

Expert
Licensed User
So.. I have been trying to make the functions "winxxx" and "controlxxxx" work, but no luck so far.
In what way do they not work? If you are expecting them to work with B4J Forms and Controls then I don't think they will as they are not native Windows controls with Windows handles but are entirely implemented at a very low level by the JavaFX framework. I don't think that .NET WPF applications can be used with AutoIt for the same reason. WPF is an independent GUI framework drawn using DirectX.
 

jmon

Well-Known Member
Licensed User
In what way do they not work?
I use it to get windows outside B4J, on the explorer. For example, if I try to get if a window called "Notepad - Untitled" exists, I would like to use the function:
B4X:
x.winExists("Notepad - Untitled", "")
But just by calling this function, B4J freezes and I have to kill B4J. It's the same with all the win and the control functions.
 

Suntzu

Member
Licensed User
jmon,

Thanks a bunch for the library! It worked like a charm. With a few tweaks, I was able to run the following on both x86 and x64 systems:

xAutoIt.winActivate("XXXXX","")
xAutoIt.winSetOnTop("XXXXX","",True)
 
Last edited:

jmon

Well-Known Member
Licensed User
jmon,

Thanks a bunch for the library! It worked like a charm. With a few tweaks, I was able to run the following on both x86 and x64 systems:

xAutoIt.winActivate("XXXXX","")
xAutoIt.winSetOnTop("XXXXX","",True)
Great! How did you do? On my computer those functions crash. Can you tell me a bit more about your setup? I think I tried on java 7, but not 8.
 

Suntzu

Member
Licensed User
On x86:

1. I downloaded the Jacob package. At the time of writing, version 1.18.
2. I created a folder name "lib" on the same folder where my JAR executable is.
3. Copied jacob-1.18-x86.dll in to the lib folder.
4. Renamed jacob-1.18-x86.dll to jacob-1.17-x86.dll.
5. Tested and it worked.

On x64:

1. I downloaded the Jacob package. At the time of writing, version 1.18.
2. I created a folder name "lib" on the same folder where my JAR executable is.
3. Copied jacob-1.18-x64.dll in to the lib folder.
4. Renamed jacob-1.18-x64.dll to jacob-1.17-x86.dll.
5. Tested and it worked.

My app was compiled on 32-bit Java 7.

Let me know if the above steps work for you.
 
Last edited:

jmon

Well-Known Member
Licensed User
On x86:

1. I downloaded the Jacob package. At the time of writing, version 1.18.
2. I created a folder name "lib" on the same folder where my JAR executable is.
3. Copied jacob-1.18-x86.dll in to the lib folder.
4. Renamed jacob-1.18-x86.dll to jacob-1.17-x86.dll.
5. Tested and it worked.

On x64:

1. I downloaded the Jacob package. At the time of writing, version 1.18.
2. I created a folder name "lib" on the same folder where my JAR executable is.
3. Copied jacob-1.18-x64.dll in to the lib folder.
4. Renamed jacob-1.18-x64.dll to jacob-1.17-x86.dll.
5. Tested and it worked.

My app was compiled on 32-bit Java 7.

Let me know if the above steps work for you.
Big Big thanks! You finally closed a bug that was open for more than a year ;-) !

I tested with Java 8u_51on 32bit on Windows 7 x64 and it works!
There is only one function that doesn't work for me, it's the winExists, but all the others work properly now :)

Thank you again !
Jmon
 
Last edited:

jmon

Well-Known Member
Licensed User
Hi,

I've recompiled the class, and I've simplified the installation instructions. There are just 3 simple steps to follow to install the library.
Now every methods work properly, so no more bug.

Please follow the steps on the post #1 and download the new libraries.

Enjoy
Jmon.
 
Last edited:

JakeBullet70

Well-Known Member
Licensed User
Just got the sample working. My biggest issue was 64bit java, once I went to 32bit all was well!!! Now time for some fun!
 

jmon

Well-Known Member
Licensed User
Last edited:

Douglas Farias

Expert
Licensed User
Hi @jmon
i m folowed the instructions.
but in your example when i compile i got this error.

Program started.
main._appstart (java line: 68)
com.jacob.com.ComFailException: Can't get object clsid from progid
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at anywheresoftware.jmon.jautoitx.jAutoItX.Initialize(jAutoItX.java:70)
at b4j.example.main._appstart(main.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:36)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
on this line
B4X:
x.Initialize
what I may have done wrong?

thx
 

jmon

Well-Known Member
Licensed User
what I may have done wrong?
Hi
I'm not sure why.

Did you register AutoIt.Dll before initializing ?
B4X:
Private Sub RegisterAutoItX As Boolean
    Dim sh As Shell
    sh.Initialize("", "regsvr32.exe", Array("/s", $""${File.Combine(File.DirApp, "/lib/AutoItX3.dll")}""$))
    Dim Result As ShellSyncResult = sh.RunSynchronous(2000)
    Return Result.Success
End Sub
Do you see 2 files in the Objects/Lib folder? (Autoitx3.dll, Jacob.dll)

Does the example provided works?

By any chance, are you running Windows 10? Because I have't tested with Win10 yet. Maybe needs to download a new version of autoit dll
 

jmon

Well-Known Member
Licensed User

Douglas Farias

Expert
Licensed User
some progress.
now when i compile show error on another place.

Waiting for debugger to connect...
Program started.
Library Version: 3.3.14.2
License link: http://opensource.org/licenses/mit-license.php
Is Admin ?: false
Mouse pos X: 391
From the clipboard: Put that to the clipboard please!
Notepad exists ?false
Error occurred on line: 78 (Main)
com.jacob.com.ComFailException: Can't map name to dispid: IniWrite
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
at com.jacob.activeX.ActiveXComponent.invoke(ActiveXComponent.java:476)
at anywheresoftware.jmon.jautoitx.jAutoItX.iniWrite(jAutoItX.java:449)
at b4j.example.main._appstart(main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.start(main.java:36)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
error is on this line
B4X:
LogMe(x.iniWrite(FileName, "Section1", "Key1", "This is the value"))
 
Top