-
-
Save kenrmayfield/7d41f50fe22fa08962d4f296ad71bbed to your computer and use it in GitHub Desktop.
Prevent your computer from showing the screensaver/locking
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
| <# This PowerShell script can simply be copied over to a "PowerShell IDE" window, and then ran for as long as you want. | |
| The time this script remains active (sending mouse events to Windows so it things you're "still there", is the number | |
| of iterations on line 6 (default: 200) multiplied by the number of seconds on line 11 (default: 290). | |
| If your computer locks/marks as Away on Skype/Teams only after 10 minutes for example, change 290 seconds to 590. | |
| #> | |
| <# If you get a "File cannot be loaded because running scripts is disabled on this system.", then type in the PowerShell ISE console: | |
| powershell -ExecutionPolicy ByPass -File filename-here.ps1 | |
| #> | |
| param($iterations = 200) | |
| $MOUSEEVENTF_MOVED = 0x00000001 ; | |
| for ($i = 0; $i -lt $iterations; $i++) { | |
| Start-Sleep -seconds 290 | |
| $Pos = [System.Windows.Forms.Cursor]::Position | |
| [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point((($Pos.X) + 1) , $Pos.Y) | |
| [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($Pos.X , $Pos.Y) | |
| $signature=@' | |
| [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)] | |
| public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); | |
| '@ | |
| $SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -PassThru | |
| $SendMouseClick::mouse_event($MOUSEEVENTF_MOVED, 0, 0, 0, 0); | |
| } | |
| <# For the curious people, here are the other mouse event ID's, in case you want to actually move the mouse few pixels to the left/right, etc. | |
| $MOUSEEVENTF_LEFTDOWN = 0x00000002 ; | |
| $MOUSEEVENTF_LEFTUP = 0x00000004 ; | |
| $MOUSEEVENTF_RIGHTDOWN = 0x00000008 ; | |
| $MOUSEEVENTF_RIGHTUP = 0x00000010 ; | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment