在 Windows 7 中从命令行控制鼠标设置

Control of mouse settings from command line in Windows 7

由于残疾,我喜欢能够从使用右手鼠标切换到左手鼠标,然后再切换回来,大约每半小时一次。从控制面板执行此操作比我希望的要慢。虽然我可以在命令行或 .bat 文件中使用 main.cpl 打开鼠标设置控制器,但我希望能够使用批处理文件完成整个左右切换。这可能吗?如果可能,怎么做?

您可以将代码复制到 PS1 文件,然后使用 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))