Automate Text Typing Using Python - Project

πŸ€– How to Automate Typing Using Python: Step-by-Step Guide with Real Use Cases




Why Automate Typing with Python?

Typing the same thing repeatedly can waste time and energy. Python automation lets you:

  • Quickly test input fields
  • Build bots or auto-responders
  • Auto-fill forms or send bulk messages

Requirements

  • 🟒 Install pyautogui using:
    pip install pyautogui

1. Basic Script to Type a Sentence

This will wait 5 seconds, type a message, and press Enter:


import pyautogui
import time

print("Starting in 5 seconds...")
time.sleep(5)

pyautogui.write("Hello, this is an automated message!")
pyautogui.press('enter')

πŸ“€ Output:

Hello, this is an automated message! is typed, then Enter is pressed.

⚠️ Read Cautions Below Before Using


2. Repeat a List of Messages 3 Times

This sends each message 3 times:


import pyautogui
import time

messages = ["Subscribe to my channel", "Like this video", "Share with friends"]

print("Typing will start in 10 seconds...")
time.sleep(10)

for message in messages:
    for _ in range(3):
        pyautogui.write(message)
        pyautogui.press('enter')
        time.sleep(0.5)

πŸ“€ Output:

  • Subscribe to my channel (3 times)
  • Like this video (3 times)
  • Share with friends (3 times)

⚠️ Read Cautions Below Before Using


3. Loop "Create Image" 100 Times

This script types a custom sentence followed by "more" multiple times:


import pyautogui
import time

print("Typing will start in 15 seconds...")
time.sleep(15)

for i in range(1, 101):
    pyautogui.write("create an image of relate to history")
    pyautogui.press('enter')
    time.sleep(11)

    for _ in range(10):
        pyautogui.write("more")
        pyautogui.press("enter")
        time.sleep(0.1)

    time.sleep(16)

πŸ’‘ Output:

  • 100 times: “create an image of relate to history”
  • After each, it types "more" 10 times

⚠️ Read Cautions Below Before Using


Use Cases

  • Send automatic WhatsApp replies
  • Post replies in YouTube live chat
  • Fill web forms automatically
  • UI/keyboard testing
  • Automate repetitive game chat

⚠️ Important Cautions

  • ✅ Open the correct Notepad, browser, or terminal window where typing should happen.
  • 🚫 Do not touch or click anywhere else once the countdown starts — the script types wherever the cursor is!
  • πŸ›‘ To stop the script immediately:
    • πŸ”§ Use Ctrl + C in the terminal to cancel
    • ❌ Or simply close the terminal window or tab

Bonus Tips

  • Always use time.sleep() before the typing starts
  • Test with small loops before running large automations
  • Use on empty Notepad or specific input box to avoid problems

Resources & Further Learning

Author: Only Python Developer & Automation Enthusiast

“In the world of code, Python is the language of simplicity, where logic meets creativity, and every line brings us closer to our goals.”— Only Python

πŸ“Œ Follow Us And Stay Updated For Daily Updates

Comments