powershell mouse move does not prevent idle mode powershell mouse move does not prevent idle mode powershell powershell

powershell mouse move does not prevent idle mode


The solution from the blog Prevent desktop lock or screensaver with PowerShell is working for me. Here is the relevant script, which simply sends a single period to the shell:

param($minutes = 60)$myshell = New-Object -com "Wscript.Shell"for ($i = 0; $i -lt $minutes; $i++) {  Start-Sleep -Seconds 60  $myshell.sendkeys(".")}

and an alternative from the comments, which moves the mouse a single pixel:

$Pos = [System.Windows.Forms.Cursor]::Position[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) + 1) , $Pos.Y)$Pos = [System.Windows.Forms.Cursor]::Position[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) - 1) , $Pos.Y)


I tried a mouse move solution too, and it likewise didn't work. This was my solution, to quickly toggle Scroll Lock every 4 minutes:

Clear-HostEcho "Keep-alive with Scroll Lock..."$WShell = New-Object -com "Wscript.Shell"while ($true){  $WShell.sendkeys("{SCROLLLOCK}")  Start-Sleep -Milliseconds 100  $WShell.sendkeys("{SCROLLLOCK}")  Start-Sleep -Seconds 240}

I used Scroll Lock because that's one of the most useless keys on the keyboard. Also could be nice to see it briefly blink every now and then. This solution should work for just about everyone, I think.

See also:


There is an analog solution to this also. There's an android app called "Timeout Blocker" that vibrates at a set interval and you put your mouse on it. https://play.google.com/store/apps/details?id=com.isomerprogramming.application.timeoutblocker&hl=en