PowerShell script that simulates human-like mouse movement
It’s a little script that moves the mouse around naturally so the computer doesn’t go idle.
If You Want to Demo It
-
Open PowerShell
-
Paste the script
-
Let them watch the cursor move
-
Stop with
Ctrl + C
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$rand = New-Object System.Random
function Ease-InOut($t) {
# Smooth acceleration curve (cosine based)
return 0.5 * (1 - [Math]::Cos($t * [Math]::PI))
}
while ($true) {
$start = [System.Windows.Forms.Cursor]::Position | Select-Object -First 1
$startX = [double]$start.X
$startY = [double]$start.Y
# Random distant target
$endX = $rand.Next(0, $screen.Width)
$endY = $rand.Next(0, $screen.Height)
# Random duration between 1.5–3 seconds
$duration = $rand.NextDouble() * 1.5 + 1.5
$steps = 120
$curveIntensity = $rand.Next(-50, 50)
for ($i = 0; $i -le $steps; $i++) {
$t = $i / $steps
$progress = Ease-InOut $t
# Linear interpolation
$currentX = $startX + ($endX - $startX) * $progress
$currentY = $startY + ($endY - $startY) * $progress
# Add slight curve (perpendicular offset)
$curveOffset = $curveIntensity * [Math]::Sin($t * [Math]::PI)
$dx = $endY - $startY
$dy = $startX - $endX
$length = [Math]::Sqrt($dx*$dx + $dy*$dy)
if ($length -ne 0) {
$currentX += ($dx / $length) * $curveOffset
$currentY += ($dy / $length) * $curveOffset
}
# Micro jitter (very small randomness)
$currentX += $rand.Next(-2,3)
$currentY += $rand.Next(-2,3)
$point = New-Object System.Drawing.Point ([int]$currentX), ([int]$currentY)
[System.Windows.Forms.Cursor]::Position = $point
Start-Sleep -Milliseconds ([int](($duration * 1000) / $steps))
}
# Random pause before next movement (20–60 sec)
Start-Sleep -Seconds ($rand.Next(5, 10))
}
Add-Type -AssemblyName System.Drawing
$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$rand = New-Object System.Random
function Ease-InOut($t) {
# Smooth acceleration curve (cosine based)
return 0.5 * (1 - [Math]::Cos($t * [Math]::PI))
}
while ($true) {
$start = [System.Windows.Forms.Cursor]::Position | Select-Object -First 1
$startX = [double]$start.X
$startY = [double]$start.Y
# Random distant target
$endX = $rand.Next(0, $screen.Width)
$endY = $rand.Next(0, $screen.Height)
# Random duration between 1.5–3 seconds
$duration = $rand.NextDouble() * 1.5 + 1.5
$steps = 120
$curveIntensity = $rand.Next(-50, 50)
for ($i = 0; $i -le $steps; $i++) {
$t = $i / $steps
$progress = Ease-InOut $t
# Linear interpolation
$currentX = $startX + ($endX - $startX) * $progress
$currentY = $startY + ($endY - $startY) * $progress
# Add slight curve (perpendicular offset)
$curveOffset = $curveIntensity * [Math]::Sin($t * [Math]::PI)
$dx = $endY - $startY
$dy = $startX - $endX
$length = [Math]::Sqrt($dx*$dx + $dy*$dy)
if ($length -ne 0) {
$currentX += ($dx / $length) * $curveOffset
$currentY += ($dy / $length) * $curveOffset
}
# Micro jitter (very small randomness)
$currentX += $rand.Next(-2,3)
$currentY += $rand.Next(-2,3)
$point = New-Object System.Drawing.Point ([int]$currentX), ([int]$currentY)
[System.Windows.Forms.Cursor]::Position = $point
Start-Sleep -Milliseconds ([int](($duration * 1000) / $steps))
}
# Random pause before next movement (20–60 sec)
Start-Sleep -Seconds ($rand.Next(5, 10))
}
Comments
Post a Comment