Have you ever imagined controlling your computer automatically, as if an invisible hand is moving the mouse, typing text, or pressing keys? With Python, that’s totally possible! One easy way to do this is by using a library called PyAutoGUI.
Below is a simple Python script that demonstrates how we can automate interactions with an app like Notepad:
import pyautogui
import time
# Move mouse to position (200, 200)
pyautogui.moveTo(200, 200)
# Click the mouse
pyautogui.click()
# Type the text
pyautogui.typewrite("Lorem Ipsum Dolor")
# Press Enter
pyautogui.press('enter')
What Does This Script Do?
This script can be used to automate typing into an application like Notepad. Assuming Notepad is already open and maximized, the script will:
- Move the mouse cursor to the screen position (200, 200),
 - Click at that location to focus the Notepad window,
 - Type the text “Lorem Ipsum Dolor”,
 - Press the Enter key.
 
How Does It Work?
The script works by simulating screen coordinates and human-like input actions:
pyautogui.moveTo(x, y)moves the mouse to a specific position on the screen.pyautogui.click()simulates a mouse click.pyautogui.typewrite()types out the given text as if a person is typing.pyautogui.press()simulates pressing a key on the keyboard.
Why Is This Useful?
This is a basic example of desktop automation, which is the ability for a computer to perform repetitive tasks automatically. With this concept, you can:
- Build office task bots,
 - Auto-write content or fill out forms,
 - Perform UI testing,
 - Even create bots for games or social media (responsibly, of course).
 
Important Notes
- This script depends on the exact window size and position of the application. Make sure Notepad is opened and maximized before running the script.
 - For more complex and stable automation, you can combine PyAutoGUI with other libraries like OpenCV to detect on-screen elements.