Today: November 28, 2021 5:35 pm

How to Automate Tasks — Robotic Process Automation with Python

In the book “Automating boring things with python”, I got to know a very useful python module: pyautogui. Thanks to this module, you can make simple RPA (robotic process automation) applications yourself, without the need of an expensive tool. This will allow you to do your work more efficiently. It is also very satisfying to see your robot working for you or for a guy in India that you have hired to do your repetitive task.

See how I used RPA to go immediately and automatically to the website, fill out forms and take screenshots.

How to automate keyboard and mouse with python

Once you have installed the pyautogui module (using the pip install pyautogui command) you can import it using this code.

import pyautogui

Mouse input

For moving your mouse you can use this code:

pyautogui.moveTo(280,20)

The first number (280) is the X-position on your screen or the amount of pixels on the left, the second number (20) the Y-position on your screen or the amount of pixels from the top. So you can control your mouse with one line of code!

You can emulate mouse clicks with following code:

pyautogui.click()

Keyboard input

If you want to type something you can us following code:

pyautogui.write(“I am a bot and I am writing”)

You can also press buttons

pyautogui.press(‘enter’)

So basically with these 2 mouse and 2 keyboard commands you are able to automate form submissions, screenshot, repetitive tasks and so on.

Great! Now save some time and automate your job.