Swapping left and right mouse button in .NET

前端 未结 3 1129
遇见更好的自我
遇见更好的自我 2020-12-30 12:46

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

3条回答
  •  时光说笑
    2020-12-30 13:41

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

提交回复
热议问题