Created
January 31, 2022 13:11
-
-
Save Stilmant/beb05636724efb9af4ed43684f336826 to your computer and use it in GitHub Desktop.
lock mouse at close range
This file contains 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 -AssemblyName System.Windows.Forms | |
[system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null | |
$c1 = [System.Windows.Forms.Cursor]::Position.X | |
$c2 = [System.Windows.Forms.Cursor]::Position.Y | |
for (;;) | |
{ | |
$p1 = [System.Windows.Forms.Cursor]::Position.X | |
$p2 = [System.Windows.Forms.Cursor]::Position.Y | |
$sRadius = 80 | |
$bRadius = [math]::Sqrt([Math]::Pow(($p1 - $c1),2) + [Math]::Pow(($p2 - $c2),2)) | |
if ( $bRadius -gt ($sRadius + 10)) | |
{ | |
$s1 = ((($p1 - $c1) * $sRadius) / $bRadius) + $c1 | |
$s2 = ((($p2 - $c2) * $sRadius) / $bRadius) + $c2 | |
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($s1, $s2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment