Sikuli is a software with internal IDE to manipulate GUI automatically. The automation and image recognition help us saves a lot of time to do many regular and trivial tasks. It is based on Java and its package Jython. In this article, you will learn the installation on the Windows platform, commonly used operations, execution of the script without launching GUI, an example of fully automatic execution. That’s get start it.
Installation
- Download and install through
.exe
from Java offline version. (version 8 update 281 is feasible) - Download SikuliX IDE (Click download the ready to use sikulix.jar) to certain directory. (version 2.0.4 is feasible)
- Download Jython to the same directory as above.
- Type the command
java -jar your_path_to_the_file
and it will launch the GUI if your installation succeed.
Operations
Quick start
- In the beginning, we have to switch the resolution to 1024*768
- Launch the Sikuli and the Windows calculator as example
- Take a screenshot to a button of the calculator
- Type the command
click(YourPicture)
and execute it.
Common operations
The sikuli IDE supports not only the intrinsic commands (e.g.click) but also the Python commands.
If you are familiar with python, you can write a sikuli script easily by simple commands such as if-else, for, while. If not, you can learn it from many resources in just several ten minutes cuz its easy. Here I list the commonly used command as following.
Commands | Input | Output |
click() | screenshot | Click the picture (Error while the picture does not exist) |
doubleClick() | screenshot | Double click the picture (Error while the picture does not exist) |
wait() | int | Wait the seconds |
exists() | screenshot | Return whether the picture exsists as bool |
region() | region | Return an object with several attributes such as click. |
type() | string | Enter the string |
Key.ENTER, KEY.SPACE, etc. | Press the keyboard |
Export the script as a program
Once you want to execute the program without artificial works (launch IDE and press the execute button), we can export the script as a program.
- Click file -> Export skl, then select the path that the Sikuli is installed. You can choose the other path but the command should specify both Sikuli and the script in next step.
- Open CMD and type the following command to execute the script.
1 | java -jar sikulixide-2.0.4.jar -r myscript.skl |
The script will be executed by the command. Furthermore, if you know how to manipulate batch file or shell script as well as the setting of automatic execution after login the desktop. You can do the whole process automatically, that is, the only thing you need to do is to turn on the computer. See more in the following example.
An example
Here is an example that I write for automatically login a game “Tower of Saviors”. To let the debug step become more convenient, I make the script write the logs. Moreover, to ensure the target picture shown on the screen, we have to wait for a few seconds before executing a next Sikuli command.
1 | import os |
P.S. The screenshots are saved in the folder C:\Users\yoor_name\Documents\first.sikuli
After we suceed to execute the script and export the script into a .skl
file in a folder (same as Sikuli folder is recommended), to execute the script automatically as you login your desktop:
Create a text file and alter the extension file name from
.txt
to.bat
at the same folder as Sikuli.Right click the
.bat
and edit it by text editor. Type the following code.
1 | cd C:\Users\your_name\Desktop\Sikuli |
Go to
C:\Users\your_name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
and create a text file followed by altering the extension file name from.txt
to.vbs
.- Scripts (
.bat
,.sh
,.vbs
, etc.) in this folder will be executed after you login. .vbs
is the caller of.bat
which let it executes without CMD windows. (It’s important cuz we don’t want the CMD windows cover the picture that detected in Sikuli script)
- Scripts (
Right click the
.vbs
and edit it by text editor. Type the following code.1
2
3Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Users\your_name\Desktop\Sikuli\startTOS.bat" & Chr(34), 0
Set WshShell = Nothingl
Now, you can logout then login. You will see the Sikuli scripts executes automatically.