在.NET中交换鼠标左右键鼠标、右键、NET

2023-09-03 13:08:59 作者:〃我2,但是我很快乐〃.

如何我换鼠标左键和右键按钮.NET(preferably C#)?基本上,如果用户通过控制面板检查在鼠标属性的切换主要和次要的按钮复选框的结果应该是一样的。我处理Windows XP中,如果有差别。

How do I swap left and right mouse buttons in .NET (preferably C#)? Basically the result should be the same as if the user checked the "Switch primary and secondary buttons" checkbox in the Mouse Properties through the control panel. I'm dealing with Windows XP, in case that makes a difference.

推荐答案

您可以使用Windows API调用来 SwapMouseButton

You can use a Windows API call to SwapMouseButton:

using System.Runtime.InteropServices;

// ...

[DllImport("user32.dll")]
public static extern Int32 SwapMouseButton(Int32 bSwap);

// ...

// Swap it.
SwapMouseButton(1); 

// Back to normal.
SwapMouseButton(0);