Created
September 18, 2025 16:06
-
-
Save jbinfo/90faaaf1c3b4eaddd214d1db9954b44f to your computer and use it in GitHub Desktop.
Stay Active – PowerShell Script to Prevent Windows Idle Lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Add-Type @" | |
| using System; | |
| using System.Runtime.InteropServices; | |
| public class NativeMethods { | |
| [DllImport("user32.dll")] | |
| public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, UIntPtr dwExtraInfo); | |
| } | |
| "@ | |
| function Move-Mouse { | |
| # Get current mouse position | |
| Add-Type -AssemblyName System.Windows.Forms | |
| $pos = [System.Windows.Forms.Cursor]::Position | |
| $x = $pos.X | |
| $y = $pos.Y | |
| # Move slightly (+1,+1) | |
| [NativeMethods]::mouse_event(0x0001, 1, 1, 0, [UIntPtr]::Zero) | |
| Start-Sleep -Milliseconds 100 | |
| # Move back to original position | |
| [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y) | |
| } | |
| while ($true) { | |
| $hour = (Get-Date).Hour | |
| if ($hour -ge 8 -and $hour -lt 18) { | |
| Move-Mouse | |
| } | |
| Start-Sleep -Seconds 60 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment