简体   繁体   中英

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?

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM