Skip to content

Instantly share code, notes, and snippets.

@Stilmant
Created January 31, 2022 13:11
Show Gist options
  • Save Stilmant/beb05636724efb9af4ed43684f336826 to your computer and use it in GitHub Desktop.
Save Stilmant/beb05636724efb9af4ed43684f336826 to your computer and use it in GitHub Desktop.
lock mouse at close range
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