Swapping left and right mouse button in .NET
如何在 .NET(最好是 C#)中交换鼠标左键和右键?基本上结果应该与用户通过控制面板选中鼠标属性中的”切换主要和次要按钮”复选框相同。我正在处理 Windows XP,以防万一。
- 你所说的交换是什么意思…你想为你自己的应用程序进行系统级交换还是交换?
您可以使用 Windows API 调用 SwapMouseButton:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
using System.Runtime.InteropServices;
// … [DllImport(“user32.dll”)] // … // Swap it. // Back to normal. |
- 谢谢。可能要添加您需要”使用 System.Runtime.InteropServices;”
- 哎呀;我确实忽略了提及这一点。我会添加它以供将来参考。
- 这有效,但用户注销后状态不会保存。要记住交换状态,您必须将 Porges 的解决方案与注册表一起使用。
类似这样的:
1
2 3 4 5 6 7 8 9 |
using Microsoft.Win32;
var key = Registry.CurrentUser.CreateSubKey(“Control Panel\\\\Mouse\”); if (newValue == null) newValue =”1″; key.SetValue(“SwapMouseButtons”, newValue, RegistryValueKind.String); |
这是执行此操作的代码片段。
来源:https://www.codenong.com/653911/