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.
You do not use
rundll32
for that.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#:Compile with:
Swap/unswap buttons:
There is hack, which can be used to configure the layout of the mouse for a left-handed user. Just run the following command:
Run this command to reconfigure the layout of the mouse for a left-handed user.
I am going to give you an explanation for this kind of behaviour:
Functions, which are called by rundll32.exe, have the following function prototype:
SwapMouseButton has the following function prototype:
SwapMouseButton uses the same calling convention (__stdcall) as every function called by rundll32.exe does.
If you call SwapMouseButton using rundll32.exe with an additional command-line, this command-line will be passed to this function as lpszCmdLine and will be ignored.
If you call that functions using rundll32, rundll32 automatically passes a valid window handle (HWND) as the first argument of the called function.
hwnd - window handle that should be used as the owner window for any windows your DLL creates
The function SwapMouseButton function called by rundll32 requires TRUE as the first argument in order to configure the layout of the mouse for a left-handed user. The valid window handle passed by rundll32.exe to SwapMouseButton within user32.dll is unequal to 0 and is defined as TRUE, when using a BOOL value.
You can find details on rundll32.exe and the prototype used by functions called by this executable here: INFO: Windows Rundll and Rundll32 Interface
You can find details about the function SwapMouseButton here: SwapMouseButton function (Windows)
I solved the same problem by searching "mouse" in the start menu. You will find an option with the same name. click it. A dialog box will appear. There untick the option "switch primary and secondary buttons" in the buttons tab with the "button configurations" box.
A shorter swapper in C:
Install Windows SDK and Compile in x86_x64 Cross Tools Command Prompt via eg.
cl swapmbtn.c "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64\user32.lib"
Rename
main
toWinMain
to prevent the console window flash.Thanks so much for the C# solution. It worked like a charm.
I made a slight alteration so that I could simply click on a desktop short-cut to toggle the primary mouse button, without passing in arguments. In case my approach helps someone else, here is that version: