B4J Library jAutoItX Library

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

  • jAutoItX_Libraries.zip
    256.4 KB · Views: 507
  • jAutoItX_Example.zip
    447.8 KB · Views: 480
Last edited:

jmon

Well-Known Member
Licensed User
error is on this line
I see other errors related to JACOB + autoit :
https://sourceforge.net/p/jacob-project/discussion/375946/thread/aeb31a06/
https://stackoverflow.com/questions...omfailexception-cant-map-name-to-dispid-inire

The first link suggests that the error comes from JNI, probably becuase the same DLL is used in different threads. By any chance do you have the example running twice at the same time?

EDIT:
try un-registering the AutoIt DLL first, then re-register it again?
B4X:
regsvr32 -u <path>\<filename>.dll

EDIT:
Are you running a 64 bit version of JDK?
 

xulihang

Active Member
Licensed User
I see other errors related to JACOB + autoit :
https://sourceforge.net/p/jacob-project/discussion/375946/thread/aeb31a06/
https://stackoverflow.com/questions...omfailexception-cant-map-name-to-dispid-inire

The first link suggests that the error comes from JNI, probably becuase the same DLL is used in different threads. By any chance do you have the example running twice at the same time?

EDIT:
try un-registering the AutoIt DLL first, then re-register it again?
B4X:
regsvr32 -u <path>\<filename>.dll

EDIT:
Are you running a 64 bit version of JDK?

com.jacob.com.ComFailException: Can't get object clsid from progid

got the same error with jdk x64 on windows10 x64
 

xulihang

Active Member
Licensed User
com.jacob.com.ComFailException: Can't co-create object

sometimes this error
 

jmon

Well-Known Member
Licensed User
got the same error with jdk x64 on windows10 x64
Hi, did you follow the instructions in first post for Java 64 bit?
  • For Java 64 bit, download jacob-x.xx-x64.dll (Click HERE), rename it to jacob.dll and replace the old dll.

Edit : did you register AutoitX?
 

xulihang

Active Member
Licensed User
Hi, did you follow the instructions in first post for Java 64 bit?


Edit : did you register AutoitX?

yes, I did. I also tried x86 JDK, but the same error again.

The compiled jar runs well on another win10 computer. Maybe it is because the environment?
 

xulihang

Active Member
Licensed User
did it with admin privilege. I have given up on it. Maybe I can just go for autoit directly...
 

jmon

Well-Known Member
Licensed User
I have given up on it
You could try a couple things:

- Could you try installing Autoit (https://www.autoitscript.com/site/autoit/downloads/), see if you still run into this problem? The installation will register the COM object properly.

- Otherwise, try registering the dll manually using Regserv32 in the command line.

- The error you are running into are related to the dll no registered properly. Check again the first post to see if you registered the dll properly and copied the files correctly.

- You could check the stdOut and stdErr of this function to see if there was a problem when registering the dll:

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)
    Log(Result.stdOut)
    Log(Result.stdErr)
    Return Result.Success
End Sub
Hope it works!
 

xulihang

Active Member
Licensed User
Hello, jmon. I have tried the autoit3 installation and the dll registration, but it did not work. Anyway, autoit3 just works great. Thank you for your help.
 

xulihang

Active Member
Licensed User
I registered the x64 version of autoit to solve the Can't get object clsid from progid error.
 

Attachments

  • AutoItX3_x64.zip
    158.8 KB · Views: 48

omarruben

Active Member
Licensed User
2021-05-02 11_21_23-Window.jpg
error , I did update all (included the one in the post #30)
 
Top