For this task, we require a simple module named pyautogui which is a GUI automation python module to control keyboard and mouse events. You can directly install by running 'pip install pyautogui' on the command shell.
spam.py
import pyautogui as ptimport timelimit = input("Enter limit:")message = input("Enter message:")i = 0time.sleep(5)while i < int(limit):pt.typewrite(message)# the message is written where -# the cursor belongspt.press("enter")i+=1
Now, you can set the limit of messages you want to send as well as the message in the Command Prompt itself. If you run this code it will give you five seconds to open WhatsApp( You can specify your time ) and point the cursor towards the message input box corresponding to the person or group you want to send messages to. The pt.typewrite( ) is a function that helps to write the messages automatically and pt.press( ) function helps to send the message by pressing enter. We are writing this inside a while loop so that it will run until it reaches the limit.
Basically, this program writes characters to which the cursor belongs. So in this case it will write the message in the message input box and press enter and we have done.
You might also like: Instagram, save posts on the gallery automatically using python