Skip to content

Instantly share code, notes, and snippets.

@mmpx12
Created September 9, 2025 12:38
Show Gist options
  • Select an option

  • Save mmpx12/e481dca93a659a470d78696707c6924f to your computer and use it in GitHub Desktop.

Select an option

Save mmpx12/e481dca93a659a470d78696707c6924f to your computer and use it in GitHub Desktop.
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Mouse {
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public struct POINT {
public int X;
public int Y;
}
}
"@
# get current position as starting point
[Mouse+POINT]$pos = New-Object Mouse+POINT
[Mouse]::GetCursorPos([ref]$pos) | Out-Null
$startX = $pos.X
$startY = $pos.Y
$size = 50 # small square side in pixels
$delay = 5 # seconds between moves
while ($true) {
# move right
[Mouse]::SetCursorPos($startX + $size, $startY)
Start-Sleep -Seconds $delay
# move down
[Mouse]::SetCursorPos($startX + $size, $startY + $size)
Start-Sleep -Seconds $delay
# move left
[Mouse]::SetCursorPos($startX, $startY + $size)
Start-Sleep -Seconds $delay
# move up (back to start)
[Mouse]::SetCursorPos($startX, $startY)
Start-Sleep -Seconds $delay
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment