Last active
May 2, 2025 20:41
-
-
Save yamgarcia/f5caec679db539e843af1d6901236527 to your computer and use it in GitHub Desktop.
Auto Mouse Mover - AntiscreenSaver
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 Mouse { | |
[DllImport("user32.dll")] | |
public static extern bool SetCursorPos(int x, int y); | |
} | |
"@ | |
function Start-AntiscreenSaver { | |
# Save the current execution policy | |
$currentPolicy = Get-ExecutionPolicy | |
# Set the execution policy to RemoteSigned | |
Set-ExecutionPolicy RemoteSigned -Scope Process | |
$screenHeight = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height | |
$screenWidth = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width | |
$targetX = $screenWidth / 2 | |
$targetY = $screenHeight | |
$timeout = New-TimeSpan -Minutes 5 | |
while ($true) { | |
$currentTime = Get-Date -Format "HH:mm:ss" | |
$randomMinute = Get-Random -Minimum 49 -Maximum 59 | |
$currentMousePosition = [System.Windows.Forms.Cursor]::Position.X | |
Start-Sleep -Milliseconds 10000 | |
if (($currentTime -gt ("07:"+$30+":30")) -and | |
($currentTime -le ("16:"+$randomMinute+":00")) | |
){ | |
Start-MoveIfSamePosition($currentMousePosition) | |
# Reset lastInputTime | |
$lastInputTime = [Environment]::TickCount | |
} | |
# Check input interval | |
Start-Sleep -Milliseconds 1000 | |
} | |
# Set the execution policy back to the original value | |
Set-ExecutionPolicy $currentPolicy -Scope Process | |
} | |
Function Start-MoveIfSamePosition { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory = $true)] | |
[string]$currentMousePosition | |
) | |
$newMousePosition = [System.Windows.Forms.Cursor]::Position.X | |
if($newMousePosition -eq $currentMousePosition){ | |
Write-Host $newMousePosition | |
Write-Host $currentMousePosition | |
# move the mouse cursor | |
[Mouse]::SetCursorPos($targetX+10, $targetY+10) | |
Start-Sleep -Seconds 1 | |
[Mouse]::SetCursorPos($targetX+50, $targetY+50) | |
} | |
} | |
Start-AntiscreenSaver |
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 the new type definition with the click method | |
Add-Type @" | |
using System; | |
using System.Runtime.InteropServices; | |
public class MouseActions { | |
[DllImport("user32.dll")] | |
public static extern bool SetCursorPos(int x, int y); | |
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] | |
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo); | |
public const int MOUSEEVENTF_LEFTDOWN = 0x02; | |
public const int MOUSEEVENTF_LEFTUP = 0x04; | |
public static void ClickLeftMouseButton(int x, int y) { | |
SetCursorPos(x, y); | |
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, 0); | |
} | |
} | |
"@ | |
function Start-AntiscreenSaver { | |
# Save the current execution policy | |
$currentPolicy = Get-ExecutionPolicy | |
# Set the execution policy to RemoteSigned | |
Set-ExecutionPolicy RemoteSigned -Scope Process | |
$screenHeight = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height | |
$screenWidth = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width | |
$targetX = $screenWidth / 2 | |
$targetY = $screenHeight | |
while ($true) { | |
$currentTime = Get-Date -Format "HH:mm:ss" | |
$randomMinute = Get-Random -Minimum 49 -Maximum 59 | |
$currentMousePosition = [System.Windows.Forms.Cursor]::Position | |
Start-Sleep -Seconds 60 | |
if (($currentTime -gt ("07:30:30")) -and ($currentTime -le ("17:" + $randomMinute + ":00"))) { | |
Start-MoveIfSamePosition -currentMousePosition $currentMousePosition -targetY $targetY -targetX $targetX | |
} | |
} | |
# Set the execution policy back to the original value | |
Set-ExecutionPolicy $currentPolicy -Scope Process | |
} | |
function Start-MoveIfSamePosition { | |
param ( | |
[Parameter(Mandatory = $true)] | |
[System.Drawing.Point]$currentMousePosition, | |
[string]$targetY, | |
[string]$targetX | |
) | |
$newMousePosition = [System.Windows.Forms.Cursor]::Position | |
if ($newMousePosition -eq $currentMousePosition) { | |
# Move the mouse cursor | |
[MouseActions]::SetCursorPos($targetX + 5, $targetY) | |
Start-Sleep -Seconds 1 | |
[MouseActions]::SetCursorPos($targetX, $targetY) | |
[MouseActions]::ClickLeftMouseButton($targetX, $targetY) | |
} | |
} | |
Start-AntiscreenSaver |
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 Mouse { | |
[DllImport("user32.dll")] | |
public static extern bool SetCursorPos(int x, int y); | |
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] | |
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo); | |
public const int MOUSEEVENTF_LEFTDOWN = 0x02; | |
public const int MOUSEEVENTF_LEFTUP = 0x04; | |
public static void ClickLeftMouseButton(int x, int y) { | |
SetCursorPos(x, y); | |
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)x, (uint)y, 0, 0); | |
} | |
} | |
"@ | |
$screenHeight = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Bottom | |
$screenWidth = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width | |
$targetY = $screenHeight -10 | |
$targetX = $screenWidth / 2 | |
function Start-AntiscreenSaver { | |
# Save the current execution policy | |
$currentPolicy = Get-ExecutionPolicy | |
# Set the execution policy to RemoteSigned | |
Set-ExecutionPolicy RemoteSigned -Scope Process | |
while ($true) { | |
$currentTime = Get-Date -Format "HH:mm:ss" | |
$randomMinute = Get-Random -Minimum 49 -Maximum 59 | |
$currentMousePosition = [System.Windows.Forms.Cursor]::Position | |
# Check input interval | |
Start-Sleep -Seconds 120 | |
if (($currentTime -gt ("07:30:30")) -and ($currentTime -le ("17:" + $randomMinute + ":00"))) { | |
Start-MoveIfSamePosition $currentMousePosition | |
} | |
} | |
# Set the execution policy back to the original value | |
Set-ExecutionPolicy $currentPolicy -Scope Process | |
} | |
function Start-MoveIfSamePosition { | |
param ( | |
[Parameter(Mandatory = $true)] | |
[System.Drawing.Point]$currentMousePosition | |
) | |
$newMousePosition = [System.Windows.Forms.Cursor]::Position | |
if ($newMousePosition -eq $currentMousePosition) { | |
# Move the mouse cursor | |
[Mouse]::SetCursorPos($currentMousePosition.X + 5, $currentMousePosition.Y) | |
Start-Sleep -Seconds 1 | |
[Mouse]::SetCursorPos($currentMousePosition.X, $currentMousePosition.Y) | |
# Simulate a mouse click | |
[Mouse]::ClickLeftMouseButton($targetX, $targetY) | |
} | |
} | |
Start-AntiscreenSaver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment