Save and restore your mouse position with PowerShell

Problem:

I need to store my mouse position so I can return it so the exact spot on my screen to fix an error during a screen recording.

Solution:

Using PowerShell version 5.x on Windows you can use the following code.

First you will need to load the correct assembly.

Add-Type -Path 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Windows.Forms.dll'

To save the location run this command.

$p = [System.Windows.Forms.Cursor]::Position

To restore your mouse position run this command.

[System.Windows.Forms.Cursor]::Position = $p

I open a PowerShell window on a different monitor. When I make a mistake I Alt+Tab to the PowerShell window and store my mouse location. When I am ready to continue I restore my mouse position and Alt+Tab back to the window I need to record.

Add comment

Loading