CrimsonDark
CrimsonDark

Reputation: 727

Control of mouse settings from command line in Windows 7

Because of a disability I like to be able to switch from using a right-hand mouse to a left-hand mouse, and back again, every half-hour or so. Doing this from the control panel is slower than I would like. Although I can open the mouse settings controller using main.cpl on the command line or in a .bat file, I'd like to to able to do the entire left-right switch using a batch file. Is this possible, and if so, how?

Upvotes: 0

Views: 663

Answers (1)

Konstantin Baklaev
Konstantin Baklaev

Reputation: 323

You can copy the code to the PS1 file and run it with Powershell:

[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

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

Upvotes: 2

Related Questions