用於交換滑鼠按鈕的鍵盤快速鍵

用於交換滑鼠按鈕的鍵盤快速鍵

我雙手使用滑鼠,出於舒適原因,我喜歡來回切換。然而,由於每次都需要經過大約無數層菜單來交換按鈕,因此這變得很困難。有沒有一種簡單的方法來創建一個鍵盤快捷鍵來交換我的滑鼠左鍵和右鍵?

編輯:我的作業系統是Windows 7。

答案1

正如 blsub6 所提到的,您可以更改註冊表值(使用從批次檔呼叫的命令):

REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 1 /f

或者

REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 0 /f

不過需要先退出才能生效

更好的解決方案是用 C# 製作一個小 .exe 來交換設置,如答案中所述這個問題

建立一個您可以呼叫的文字文件swapmouse.cs,其中包含:

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

swapmouse.exe並使用以下命令將其編譯為:

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

在較新版本的 .NET 中,您可能需要新增/out:swapmouse.exe/target:exe

"[%SystemRoot%]\Microsoft.NET\Framework64\[version]\csc" /out:swapmouse.exe /target:exe swapmouse.cs

然後您只需雙擊該 exe 即可交換滑鼠按鈕。立即生效。

或者,正如 rad 所提到的,您可以建立一個快捷方式,並在其屬性的快捷方式標籤中定義鍵盤快捷鍵/熱鍵。

答案2

更好的AHK代碼:

Run, main.cpl
Send, {Space}{Enter}

我也用雙手滑鼠,也有Win7,這個程式碼很好用!

答案3

這是Autohotkey版本(修改/基於https://github.com/jNizM/AHK_DllCall_WinAPI/blob/master/src/Mouse%20Input%20Functions/SwapMouseButton.ahk)。

; autohotkey code - mapped to F12
F12::
    buttonState := DllCall("user32.dll\SwapMouseButton", "UInt", 1)
    if buttonState <> 0
    {
        buttonState := DllCall("user32.dll\SwapMouseButton", "UInt", 0)
    }

這適用於所有 Windows(包括 Windows 10)。我通常將其映射到鍵盤上的“F12”鍵等熱鍵(使用 Autohotkey),並且我可以通過按一個鍵立即在滑鼠左鍵和右鍵之間切換。無需載入控制面板或設定註冊表/重新啟動。

答案4

在 Windows Vista(也許 7)及更高版本上切換滑鼠按鈕的鍵盤方式:

  1. Windows 鍵
  2. 輸入“滑鼠”
  3. 空白鍵
  4. 進入

是的,按了 8 個按鍵,但還不錯……我已經按了很多次了

相關內容