Skip to content

Instantly share code, notes, and snippets.

@AnatomicJC
Created August 9, 2023 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnatomicJC/857199c146918b0782710c5f730b0f6f to your computer and use it in GitHub Desktop.
Save AnatomicJC/857199c146918b0782710c5f730b0f6f to your computer and use it in GitHub Desktop.
Prevent desktop lock or screensaver with PowerShell
Add-Type -AssemblyName System.Windows.Forms

$sleep = 240

$i = 0
while ($true) {
  $Pos = [System.Windows.Forms.Cursor]::Position
  if (($i % 2) -eq 0) {
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) + 1) , $Pos.Y)
  }
  else {
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) - 1) , $Pos.Y)
  }
  $i++
  Start-Sleep -Seconds $sleep
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment