2

I've tried

RUNDLL32.EXE USER32.DLL,SwapMouseButton

But it doesn't work, even when run as administrator.

My goal is to make a .bat file that I can call via my fancy shmancy new mouse I bought that allows me to call any arbitrary command from a mouse click.

1
  • 1
    This command works perfectly for me. You do not need to run this command as an administrator, because the setting of the mouse layout is saved under HKCU in the registry. Jun 25, 2015 at 8:08

3 Answers 3

2

Swap mouse buttons from command line

We can swap mouse buttons by editing the registry value SwapMouseButtons under the registry key HKEY_CURRENT_USER\Control Panel\Mouse. To swap mouse buttons we need to set its value to 1.

Same thing can be done from command line using the below command.

reg add "HKEY_CURRENT_USER\Control Panel\Mouse" /v SwapMouseButtons /t REG_SZ /d 1

It requires a logoff or reboot to make the changes effective.

Reference Swap mouse buttons from command line:


Alternative Solution

How do I use Rundll32 to swapmousebutton? for a C# solution (requires the .NET Framework Runtime to be installed)

3
  • 1
    Unfortunately, by doing this, it requires a reboot. Which doesn't work since I want to be able to call this at will during work.
    – Jonathan
    Dec 27, 2014 at 8:51
  • Please edit your question to include this new requirement... :/
    – DavidPostill
    Dec 27, 2014 at 8:53
  • @JonathanLeaders alternative solution added
    – DavidPostill
    Dec 27, 2014 at 9:02
0

I used the text below on windows 10 and saved it as sandbox_mouse_button_swap.wsb

Double-clicking that file opens up the sandbox with the mouse buttons swapped, no reboot required.

<Configuration>
  <LogonCommand>
    <Command>rundll32.exe user32.dll,SwapMouseButton</Command>
  </LogonCommand>
</Configuration>
0

I am no expert at this - I tried both the above solutions but it did not work and so I simply created a .bat file with the following command script, saved it to my Desktop and whenever I want to swap, I double-click the script to make it run and it does the job for me.

rundll32.exe user32.dll,SwapMouseButton

1
  • That's exactly what OP used!
    – Toto
    Nov 17, 2022 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.