Tutorials
Calculator
The completed project is available here: Download
.
This is a short script that will allow you to familiarize yourself with the basic pysikuli’s features.
Firstly, import pysikuli
and Key
class:
import pysikuli as sik
from pysikuli import Key
Now, lets take 3 screenshot of calculator’s 2
, +
and =
buttons and save them in /pics
folder in project root directory.
At this step, it is more convenient and faster to use Paste Image for this purpose. However the tutorial can be repeated without it
Captured pics:
Then add them to the script:
if __name__ == "__main__":
pic_2 = "pics/pic_2.png"
pic_plus = "pics/pic_plus.png"
pic_equal = "pics/pic_equal.png"
To run calculator let’s use the most common way:
Press the Win
key, write a calculator
and press Enter
to apply.
In code:
sik.tap(Key.win), sik.sleep(0.02)
sik.paste("calculator"), sik.sleep(0.3)
sik.tap(Key.enter)
Note
The sik.sleep(...)
value can be various and depend on your PC reaction.
You can test several values and choose your favorites
Now, we can start clicking on calculator’s button
sik.click(pic_2, precision=0.9)
sik.click(pic_plus)
sik.click(pic_2, precision=0.9)
sik.click(pic_equal)
Note
if the click()
function couldn’t find the buttons or missed,
you can increase the precision or take another screenshot
with more details
Completed code below:
import pysikuli as sik
from pysikuli import Key
if __name__ == "__main__":
pic_2 = "pics/pic_2.png"
pic_plus = "pics/pic_plus.png"
pic_equal = "pics/pic_equal.png"
sik.tap(Key.win), sik.sleep(0.02)
sik.paste("calculator"), sik.sleep(0.3)
sik.tap(Key.enter)
sik.click(pic_2, precision=0.9)
sik.click(pic_plus)
sik.click(pic_2, precision=0.9)
sik.click(pic_equal)
Result: