Fun: Keep-Alive Mouse

Fun: Keep-Alive Mouse

  •  
  •  
  • 1
  •  
  • 1
  •  
    2
    Shares

This week I wanted to do something a little bit fun.  You’ve probably seen scripts that keep your mouse moving so your machine doesn’t go to sleep…

But have you ever seen one with PowerShell?

Yes, with the [System.Windows.Forms.Cursor] type, you can move the mouse.  Perfect!

Here’s a quick little script I put together to do just that:

Add-Type -AssemblyName System.Windows.Forms

# Get max window size for primary monitor
$WindowSize = [System.Windows.Forms.Screen]::GetWorkingArea(0)
$MaxWidth = $WindowSize.Width
$MaxHeight = $WindowSize.Height

# Loop and update mouse position until you press Ctrl-C or close the console window
while ($true)
{
     $Pos = [System.Windows.Forms.Cursor]::Position
     $x = (Get-Random -Minimum 0 -Maximum $MaxWidth)
     $y = (Get-Random -Minimum 0 -Maximum $MaxHeight)
     Write-Host "`rNew position: x:$($x),y:$($y)" -NoNewLine
     [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
     Start-Sleep -Seconds 10
}

Now, who moved my cheese?

Published by Aaron Guilmette

Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.