如何在.NET中交换左右鼠标按钮(最好是C#)?基本上结果应该与用户通过控制面板选中鼠标属性中的“切换主按钮和辅助按钮”复选框相同。我正在处理Windows XP,以防万一。
答案 0 :(得分:13)
您可以使用对SwapMouseButton
的Windows API调用:
using System.Runtime.InteropServices;
// ...
[DllImport("user32.dll")]
public static extern Int32 SwapMouseButton(Int32 bSwap);
// ...
// Swap it.
SwapMouseButton(1);
// Back to normal.
SwapMouseButton(0);
答案 1 :(得分:3)
这样的事情:
using Microsoft.Win32;
var key = Registry.CurrentUser.CreateSubKey("Control Panel\\Mouse\\");
var newValue = key.GetValue("SwapMouseButtons");
if (newValue == null) newValue = "1";
else newValue = Int32.Parse(newValue) == 1 ? "0" : "1";
key.SetValue("SwapMouseButtons", newValue, RegistryValueKind.String);
答案 2 :(得分:1)