Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Simple Automation with Python and PyAutoGUI

Posted on April 22, 2025 by Habibie

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:

  1. Move the mouse cursor to the screen position (200, 200),
  2. Click at that location to focus the Notepad window,
  3. Type the text “Lorem Ipsum Dolor”,
  4. 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.
Post Views: 339
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme