# Explicit local mouse recording. No network, window titles, text, or key logging. param([Parameter(Mandatory=$true)][int]$Left,[Parameter(Mandatory=$true)][int]$Top,[Parameter(Mandatory=$true)][int]$Width,[Parameter(Mandatory=$true)][int]$Height,[string]$OutputPath='./sm-recorder-cursor.json') $ErrorActionPreference='Stop' if($Width -le 0 -or $Height -le 0){throw 'Use positive region width and height.'} if(Test-Path -LiteralPath $OutputPath){throw 'Output already exists. Choose a new path.'} Add-Type @' using System; using System.Runtime.InteropServices; public static class RecorderMouse { [StructLayout(LayoutKind.Sequential)] public struct Point {public int X;public int Y;} [DllImport("user32.dll")] public static extern bool GetCursorPos(out Point point); [DllImport("user32.dll")] public static extern short GetAsyncKeyState(int key); } '@ $points=[System.Collections.Generic.List[object]]::new();$watch=[System.Diagnostics.Stopwatch]::StartNew();$lastMove=-1.0;$down=$false;$dropped=0 Write-Host 'Start Recorder now; stop this cursor logger with F9. This logger does not control Recorder. Align the two start times using the import offset.' try { while($watch.Elapsed.TotalSeconds -lt 7200){ if(([RecorderMouse]::GetAsyncKeyState(0x78) -band 0x8000) -ne 0){break} $point=[RecorderMouse+Point]::new();if(-not [RecorderMouse]::GetCursorPos([ref]$point)){throw 'Cursor position unavailable.'} $now=$watch.Elapsed.TotalSeconds;$pressed=([RecorderMouse]::GetAsyncKeyState(1) -band 0x8000) -ne 0;$click=$pressed -and -not $down;$down=$pressed $x=($point.X-$Left)/[double]$Width;$y=($point.Y-$Top)/[double]$Height if($x -ge 0 -and $x -le 1 -and $y -ge 0 -and $y -le 1 -and ($click -or $now-$lastMove -ge .5)){ $kind=if($click){'click'}else{'move'};if($points.Count -lt 24000){$points.Add(@{time=$now;x=$x;y=$y;kind=$kind})}else{$dropped++};if(-not $click){$lastMove=$now} } Start-Sleep -Milliseconds 15 } } finally { $watch.Stop();$payload=@{format='sm-recorder-cursor';version=1;path=@{version=1;source='desktop-import';samples=$points.ToArray();dropped=$dropped}}|ConvertTo-Json -Depth 8 $bytes=[System.Text.UTF8Encoding]::new($false).GetBytes($payload);$file=[System.IO.File]::Open($OutputPath,[System.IO.FileMode]::CreateNew,[System.IO.FileAccess]::Write) try{$file.Write($bytes,0,$bytes.Length)}finally{$file.Dispose()};Write-Host ('Saved '+$points.Count+' cursor points to '+$OutputPath) }