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:
- Download and install AutoHotkey from https://www.autohotkey.com/.
- Create a new text file with a
.ahkextension. - 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
- 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:
- Install PyAutoGUI:
pip install pyautogui
- 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:
- 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.