如何使用Rundll32交换按钮?

时间:2011-01-24 04:42:05

标签: windows mouse rundll32

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

来自MSDN的SwapMouseButton Function

  

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

     

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

运行它
RUNDLL32.EXE user32.dll,SwapMouseButton *
     

星号在这里的地方是参数应该去的地方。我已经运行它没有参数,它交换了我的左右鼠标按钮(似乎TRUE是布尔参数的默认条目)。现在我要撤消它。   但是我已经尝试了每一个在参数中传递FALSE,并且没有一个工作(没有设置我的鼠标按钮恢复正常)。

     
      
  • ˚F
  •   
  • ˚F
  •   
  •   
  •   
  • FALSE
  •   
  • “假”
  •   
  • “假”
  •   
  • “FALSE”
  •   
  • 0
  •   
  • -1
  •   
     

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

5 个答案:

答案 0 :(得分:13)

do not使用rundll32

  

Q164787:信息:Windows Rundll和Rundll32界面

     

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


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

编译:

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

交换/取消交换按钮:

swap
swap /u

答案 1 :(得分:13)

非常感谢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
        }
    }
}

答案 2 :(得分:3)

有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使用与rundll32.exe调用的每个函数相同的调用约定(__stdcall)。

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

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

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

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

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

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

答案 3 :(得分:1)

C中较短的交换者:

#include <windows.h>

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

    return 0;  
}

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

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

答案 4 :(得分:0)

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