Windows – Powershell or other script to swap mouse buttons

boot-campmacmousewindows 7

I'm wondering if this is possible. I use a Macbook, running Windows 7…when I don't have an external mouse connected, I leave the left/right settings of the buttons to the default. But when I plug in a mouse, I change that setting (since I use the mouse left-handed).

What I'd like is a simple Powershell script, or Windows script or something along those lines that I could keep on the desktop and run at the appropriate time. I don't necessarily care about having it automatic (when I plug in or remove the mouse).

Best Answer

I tried this PowerShell on a Windows PC; I don't have a Windows setup on my BootCamp to test your exact scenario.

It swapped my buttons for the mouse only. It left the touchpad and pointing stick right-handed.

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

$SwapButtons = Add-Type -MemberDefinition @'
[DllImport("user32.dll")]
public static extern bool SwapMouseButton(bool swap);
'@ -Name "NativeMethods" -Namespace "PInvoke" -PassThru

Write-Host "Mouse buttons currently swapped?" ([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)

[bool]$returnValue = $SwapButtons::SwapMouseButton(!([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped))

Write-Host "Mouse buttons currently swapped?" ([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)
Related Question