Created
September 9, 2025 12:38
-
-
Save mmpx12/e481dca93a659a470d78696707c6924f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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