windowsmouserundll32

How do I use Rundll32 to swapmousebutton?


I'm repeating a question from another forum, as I'd like the same answer.

From MSDN's SwapMouseButton Function.

How do I pass boolean data from command prompt through rundll32.exe to a boolean type argument in a command running from user32.dll?

I'm trying to run this from CMD (the command prompt)

RUNDLL32.EXE user32.dll,SwapMouseButton *

Where the asterisk is here is where the argument should go. I already ran it without an argument and it swapped my left and right mouse buttons (seems TRUE is the default entry for the boolean argument). Now I want to undo it. However I've tried each of these for passing FALSE in the argument, and none have worked (none set my mouse buttons back to normal).

  • F
  • f
  • false
  • False
  • FALSE
  • "false"
  • "False"
  • "FALSE"
  • 0
  • -1

Please help me pass the argument as needed. Thanks in advance.


Solution

  • You do not use rundll32 for that.

    Q164787: INFO: Windows Rundll and Rundll32 Interface

    [...] Rundll and Rundll32 programs do not allow you to call any exported function from any DLL. For example, you can not use these utility programs to call the Win32 API (Application Programming Interface) calls exported from the system DLLs. The programs only allow you to call functions from a DLL that are explicitly written to be called by them.


    If you have the .NET Framework Runtime installed, it comes with compilers for several languages (for example, %SystemRoot%\Microsoft.NET\Framework64\v3.5\csc.exe for the v3.5 C# compiler on 64-bit systems). You can write a program in C#:

    using System.Runtime.InteropServices;
    using System;
    
    class SwapMouse {
        [DllImport("user32.dll")]
        public static extern Int32 SwapMouseButton(Int32 bSwap);
        static void Main(string[] args) {
            if (args.Length > 0 && String.Compare(args[0], "/u", true) == 0)
                SwapMouseButton(0);
            else
                SwapMouseButton(1);
        }
    }
    

    Compile with:

    "%SystemRoot%\Microsoft.NET\Framework64\v3.5\csc" swap.cs
    

    Swap/unswap buttons:

    swap
    swap /u