Skip to content

Instantly share code, notes, and snippets.

@bender-the-greatest
Created May 19, 2017 18:20
Show Gist options
  • Save bender-the-greatest/731527dedaaa00dd42a6ace17ba62d66 to your computer and use it in GitHub Desktop.
Save bender-the-greatest/731527dedaaa00dd42a6ace17ba62d66 to your computer and use it in GitHub Desktop.
Script to subtly move the mouse one pixel on an interval in alternating directions.
[CmdletBinding()]
Param()
Add-Type -AssemblyName System.Windows.Forms
Function WaitForKey {
Write-Host 'Press any key to continue...'
[void]$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
$MAX_MINS = 1440 # Max time in minutes this script can execute
$SLEEP_SECS = 300 # How long in seconds to wait before moving the mouse again
$pix_move = 1
$start_time = Get-Date
Write-Host "This script will terminate in ${MAX_MINS} minute(s)"
try {
while( $True ) {
Write-Verbose 'Moving cursor...'
$currentPosition = [System.Windows.Forms.Cursor]::Position
[System.Windows.Forms.Cursor]::Position = `
New-Object System.Drawing.Point( ( ( $currentPosition.X ) + $pix_move ), `
$currentPosition.Y )
if ( $start_time.AddMinutes( $MAX_MINS ) -le ( Get-Date ) ) {
Write-Verbose "Limit of ${MAX_MINS} has been reached. Exiting..."
WaitForKey
# Exit cleanly
exit 0
}
$pix_move *= -1
Write-Verbose "Sleeping for ${SLEEP_SECS} second(s)..."
sleep -s $SLEEP_SECS
}
} catch {
Write-Error $_
WaitForKey
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment