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

发布于 2024-10-14 08:42:05 字数 701 浏览 3 评论 0原文

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

来自 MSDN 的 SwapMouseButton 函数

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

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

RUNDLL32.EXE user32.dll,SwapMouseButton *

这里星号所在的位置就是参数应该去的地方。我已经在没有参数的情况下运行了它,并且它交换了我的鼠标左键和右键(似乎 TRUE 是布尔参数的默认条目)。现在我想撤消它。 然而,我已经尝试过在参数中传递 FALSE 的每一个,但没有一个起作用(没有一个将我的鼠标按钮设置回正常)。

  • F
  • f
  • 错误
  • 错误
  • “假”
  • “错误”
  • “错误”
  • 0
  • -1

请帮我根据需要传递论点。提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夏花。依旧 2024-10-21 08:42:05

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

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

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
        }
    }
}

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:

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
        }
    }
}
三生路 2024-10-21 08:42:05

为此使用 rundll32

Q164787:信息:Windows Rundll 和 Rundll32 接口

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


如果您安装了 .NET Framework 运行时,它会附带多种语言的编译器(例如,v3.5 的 %SystemRoot%\Microsoft.NET\Framework64\v3.5\csc.exe 64 位系统上的 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);
    }
}

编译方式:

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

Swap /取消交换按钮:

swap
swap /u

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
笙痞 2024-10-21 08:42:05

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

rundll32.exe user32.dll,SwapMouseButton

运行此命令可为左撇子用户重新配置鼠标布局。

我将为您解释这种行为:

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

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

SwapMouseButton 具有以下函数原型:

BOOL WINAPI SwapMouseButton(
  _In_ BOOL fSwap
)

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

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

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

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

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

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

您可以找到有关函数 SwapMouseButton 在这里:
SwapMouseButton 函数 (Windows)

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

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:

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

SwapMouseButton has the following function prototype:

BOOL WINAPI SwapMouseButton(
  _In_ BOOL fSwap
)

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)

半夏半凉 2024-10-21 08:42:05

C 中的较短交换器:

#include <windows.h>

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

    return 0;  
}

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

main 重命名为WinMain 防止控制台窗口闪烁。

A shorter swapper in 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"

Rename main to WinMain to prevent the console window flash.

陪你到最终 2024-10-21 08:42:05

下面是一个简单的 C/C++ Windows 应用程序的代码:

// SwapMouseButtons.cpp - Inversion of mouse buttons

#include <Windows.h>
#include <iostream>
#include <WinUser.h>
#include <string.h>

void main(int nArgs, char* szArguments[])
{
    if (nArgs > 1 && (_strcmpi(szArguments[1], "FALSE") == 0 || _strcmpi(szArguments[1], "F") == 0
            || _strcmpi(szArguments[1], "RIGHT") == 0 || _strcmpi(szArguments[1], "R") == 0
            || _strcmpi(szArguments[1], "0") == 0)) { // Right handed
        SwapMouseButton(false);
        std::cout << "Mouse buttons set for Right handed (default) usage\n";
        return;
    }
    if (nArgs > 1 && (_strcmpi(szArguments[1], "TRUE") == 0 || _strcmpi(szArguments[1], "T") == 0
            || _strcmpi(szArguments[1], "LEFT") == 0 || _strcmpi(szArguments[1], "L") == 0 
            || _strcmpi(szArguments[1], "1") == 0)) { // Left handed
        SwapMouseButton(true);
        std::cout << "Mouse buttons set for Left handed (inverted) usage\n";
        return;
    }
    // No option selected => help
    std::cout << "Swap Mouse Buttons\nUsage: SwapMouseButtons x\nOptions for x:\n  - False, F, Right, R or 0 for left handed usage (default usage)\n  - True, T, Left, L or 1 for right handed usage (inverted usage)\n\n";
}

编译版本 (x86) 可以在这里找到: http://micromeg.free.fr/english/progs.html

Here is the code for a simple C/C++ Windows application :

// SwapMouseButtons.cpp - Inversion of mouse buttons

#include <Windows.h>
#include <iostream>
#include <WinUser.h>
#include <string.h>

void main(int nArgs, char* szArguments[])
{
    if (nArgs > 1 && (_strcmpi(szArguments[1], "FALSE") == 0 || _strcmpi(szArguments[1], "F") == 0
            || _strcmpi(szArguments[1], "RIGHT") == 0 || _strcmpi(szArguments[1], "R") == 0
            || _strcmpi(szArguments[1], "0") == 0)) { // Right handed
        SwapMouseButton(false);
        std::cout << "Mouse buttons set for Right handed (default) usage\n";
        return;
    }
    if (nArgs > 1 && (_strcmpi(szArguments[1], "TRUE") == 0 || _strcmpi(szArguments[1], "T") == 0
            || _strcmpi(szArguments[1], "LEFT") == 0 || _strcmpi(szArguments[1], "L") == 0 
            || _strcmpi(szArguments[1], "1") == 0)) { // Left handed
        SwapMouseButton(true);
        std::cout << "Mouse buttons set for Left handed (inverted) usage\n";
        return;
    }
    // No option selected => help
    std::cout << "Swap Mouse Buttons\nUsage: SwapMouseButtons x\nOptions for x:\n  - False, F, Right, R or 0 for left handed usage (default usage)\n  - True, T, Left, L or 1 for right handed usage (inverted usage)\n\n";
}

Compiled version (x86) can be found here: http://micromeg.free.fr/english/progs.html

哎呦我呸! 2024-10-21 08:42:05

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文