windows 如何使用 Rundll32 交换鼠标按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4806575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:04:33  来源:igfitidea点击:

How do I use Rundll32 to swapmousebutton?

windowsmouserundll32

提问by TJR

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

我在另一个论坛重复一个问题,因为我想要相同的答案。

From MSDN's SwapMouseButton Function.

来自 MSDN 的SwapMouseButton 函数

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.

如何将布尔数据从命令提示符通过 rundll32.exe 传递到从 user32.dll 运行的命令中的布尔类型参数?

我正在尝试从 CMD(命令提示符)运行它

RUNDLL32.EXE user32.dll,SwapMouseButton *

星号在这里的地方就是论证应该去的地方。我已经在没有参数的情况下运行它并且它交换了我的左右鼠标按钮(似乎 TRUE 是布尔参数的默认条目)。现在我想撤销它。但是,我已经尝试了其中的每一个以在参数中传递 FALSE,但都没有奏效(没有将我的鼠标按钮设置为正常)。

  • F
  • F
  • 错误的
  • 错误的
  • 错误的
  • “错误的”
  • “错误的”
  • “错误的”
  • 0
  • -1

请帮助我根据需要传递参数。提前致谢。

回答by Irgendwer

Thanks so much for the C# solution. It worked like a charm.

非常感谢 C# 解决方案。它就像一个魅力。

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:

我做了一个小改动,这样我就可以简单地单击桌面快捷方式来切换主鼠标按钮,而无需传入参数。如果我的方法可以帮助其他人,这里是那个版本:

using System.Runtime.InteropServices;
using System;

class SwapMouse
{
    [DllImport("user32.dll")]
    public static extern Int32 SwapMouseButton(Int32 bSwap);

    static void Main(string[] args)
    {
        int rightButtonIsAlreadyPrimary = SwapMouseButton(1);
        if (rightButtonIsAlreadyPrimary != 0)
        {
            SwapMouseButton(0);  // Make the left mousebutton primary
        }
    }
}

回答by user1686

You do notuse rundll32for that.

使用rundll32了点。

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.

Q164787:信息:Windows Rundll 和 Rundll32 接口

[...]Rundll 和 Rundll32 程序不允许您从任何 DLL 调用任何导出的函数。例如,您不能使用这些实用程序来调用从系统 DLL 导出的 Win32 API(应用程序编程接口)调用。这些程序只允许您从 DLL 中调用函数,这些函数被显式编写为由它们调用。



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

如果您安装了 .NET Framework Runtime,它会附带多种语言的编译器(例如,%SystemRoot%\Microsoft.NET\Framework64\v3.5\csc.exe用于 64 位系统上的 v3.5 C# 编译器)。你可以用 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

回答by Norbert Willhelm

There is hack, which can be used to configure the layout of the mouse for a left-handed user. Just run the following command:

有 hack,可用于为惯用左手的用户配置鼠标的布局。只需运行以下命令:

rundll32.exe user32.dll,SwapMouseButton

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:

由 rundll32.exe 调用的函数具有以下函数原型:

void CALLBACK  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

SwapMouseButton has the following function prototype:

SwapMouseButton 有如下函数原型:

BOOL WINAPI SwapMouseButton(
  _In_ BOOL fSwap
)

SwapMouseButton uses the same calling convention (__stdcall) as every function called by rundll32.exe does.

SwapMouseButton 使用与 rundll32.exe 调用的每个函数相同的调用约定 (__stdcall)。

If you call SwapMouseButton using rundll32.exe with an additional command-line, this command-line will be passed to this function as lpszCmdLineand will be ignored.

如果您使用带有附加命令行的 rundll32.exe 调用 SwapMouseButton,则此命令行将作为lpszCmdLine传递给此函数,并将被忽略。

If you call that functions using rundll32, rundll32 automatically passes a valid window handle (HWND) as the first argument of the called function.

如果您使用 rundll32 调用该函数,rundll32 会自动传递一个有效的窗口句柄 (HWND) 作为被调用函数的第一个参数。

hwnd - window handle that should be used as the owner window for any windows your DLL creates

hwnd - 应用作 DLL 创建的任何窗口的所有者窗口的窗口句柄

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.

rundll32 调用的 SwapMouseButton 函数需要 TRUE 作为第一个参数,以便为惯用左手的用户配置鼠标的布局。当使用 BOOL 值时,rundll32.exe 传递给 user32.dll 中的 SwapMouseButton 的有效窗口句柄不等于 0,并被定义为 TRUE。

You can find details on rundll32.exe and the prototype used by functions called by this executable here: INFO: Windows Rundll and Rundll32 Interface

您可以在此处找到有关 rundll32.exe 和此可执行文件调用的函数使用的原型的详细信息: 信息:Windows Rundll 和 Rundll32 接口

You can find details about the function SwapMouseButton here: SwapMouseButton function (Windows)

您可以在此处找到有关SwapMouseButton 函数的详细信息: SwapMouseButton 函数 (Windows)

回答by Jan Sommer

A shorter swapper in C:

C 中更短的交换器:

#include <windows.h>

int main()  
{
    if (SwapMouseButton(TRUE))
        SwapMouseButton(FALSE);

    return 0;  
}

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"

安装 Windows SDK 并通过例如 x86_x64 跨工具命令提示符编译。 cl swapmbtn.c "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64\user32.lib"

Rename mainto WinMainto prevent the console window flash.

重命名mainWinMain以防止控制台窗口闪烁。

回答by dravog

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.

我通过在开始菜单中搜索“鼠标”解决了同样的问题。您会找到一个具有相同名称的选项。点击它。将出现一个对话框。在带有“按钮配置”框的按钮选项卡中取消勾选“切换主要和次要按钮”选项。