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

How to automate simple mouse movements and clicks

Posted on March 28, 2025March 28, 2025 by Habibie

You can automate simple mouse movements and clicks repeatedly in Windows using various tools and programming languages. Here are some methods:

1. Using AutoHotkey (AHK)

AutoHotkey is a lightweight scripting language for automating Windows tasks.

Steps:

  1. Download and install AutoHotkey from https://www.autohotkey.com/.
  2. Create a new text file with a .ahk extension.
  3. Add the following script:
#Persistent
SetTimer, ClickLoop, 1000  ; Repeat every 1000ms (1 second)
return

ClickLoop:
    MouseMove, 500, 300  ; Move the cursor to X=500, Y=300
    Click               ; Perform a left click
return
  1. Save the file and double-click it to run.

2. Using Python with PyAutoGUI

If you prefer Python, you can use the pyautogui library.

Steps:

  1. Install PyAutoGUI:
pip install pyautogui
  1. Create a Python script (mouse_automation.py):
import pyautogui
import time

while True:
    pyautogui.moveTo(500, 300)  # Move to position (500, 300)
    pyautogui.click()  # Perform a left click
    time.sleep(1)  # Wait for 1 second

Run the script:

python mouse_automation.py

3. Using Windows PowerShell

You can also use PowerShell to automate mouse clicks.

Steps:

  1. Open Notepad and paste the following code:
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Mouse {
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public static void Click(int x, int y) {
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
"@ -Language CSharp -PassThru | Out-Null
while ($true) {
[Mouse]::Click(500, 300)
Start-Sleep -Seconds 1
}

Save it as clicker.ps1.

Run it in PowerShell with:

powershell -ExecutionPolicy Bypass -File clicker.ps1

Which One to Choose?

  • AutoHotkey → Best for beginners, simple automation.
  • Python (PyAutoGUI) → More flexibility, ideal for programmers.
  • PowerShell → Works without additional installations, useful for quick scripts.
Post Views: 157
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