Keyboard Shortcut to Swap Mouse Buttons
Solution 1
As blsub6 mentioned, you can change a registry value (with a command called from a batch file):
REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 1 /f
or
REG ADD "HKCU\Control Panel\Mouse" /t REG_SZ /v SwapMouseButtons /d 0 /f
However, you need to logout before it will take effect.
The better solution is to make a tiny .exe with C# to swap the setting, as described in the answers to this question.
Make a text file which you can call swapmouse.cs
, containing this:
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
}
}
}
And compile it to swapmouse.exe
with this command:
"%SystemRoot%\Microsoft.NET\Framework64\v3.5\csc" swapmouse.cs
In more recent versions of .NET you may need to add /out:swapmouse.exe
and /target:exe
:
"[%SystemRoot%]\Microsoft.NET\Framework64\[version]\csc" /out:swapmouse.exe /target:exe swapmouse.cs
Then you just double-click that exe to swap the mouse buttons. It takes effect immediately.
Or, as rad mentions, you can create a shortcut, and define a keyboard shortcut/hotkey in the Shortcut tab of it's Properties.
Solution 2
This is the Autohotkey version (modified/based on 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)
}
This works fine with all Windows (including Windows 10). I usually map it to a hotkey such as "F12" key on my keyboard (using Autohotkey), and I can toggle between left and right mouse button instantly with press of a key. There's no need to muck with loading Control panel or setting registry / rebooting.
Solution 3
The better AHK code:
Run, main.cpl
Send, {Space}{Enter}
I also use mouse with both hands and also have Win7, this code works nice!
Solution 4
Here's an app for that: http://code.google.com/p/mouseswap/
If you have AutoIt installed, here's the script to run in an au3 file:
#NoTrayIcon HotKeySet("#a","MouseSwap") Global $Buttons While 1 Sleep(50) WEnd Func MouseSwap() If $Buttons = 0 Then DllCall("user32.dll", "int", "SwapMouseButton", "int", 1) $Buttons = 1 SplashTextOn("","E8",280,180,-1,-1,33,"Wingdings",80) Sleep(600) SplashOff() Else DllCall("user32.dll", "int", "SwapMouseButton", "int", 0) $Buttons = 0 SplashTextOn("","8F",280,180,-1,-1,33,"Wingdings",80) Sleep(600) SplashOff() EndIf EndFunc
Solution 5
Keyboard way of switching mouse buttons on Windows Vista (perhaps 7) and above:
- Windows Key
- type "mouse"
- Spacebar
- Enter
Yeah, it's 8 key presses but not too bad... I've done it a bunch
Related videos on Youtube
dsimcha
Updated on September 17, 2022Comments
-
dsimcha over 1 year
I use my mouse with both hands and like to switch back and forth for comfort reasons. However, this is made difficult by needing to go through about a zillion layers of menus to swap the buttons each time. Is there an easy way to create a single keyboard shortcut that would swap my left and right mouse button?
Edit: My OS is Windows 7.
-
Synetech over 10 yearsThat’s no good, simply changing the registry entry has no effect; the buttons remain unchanged. You would need to reboot or log out and back in for them to take effect.
-
Mica about 10 yearsThe exe is just a compiled AutoIt script (similar to AutoHotkey). Instead of the exe, you could run the au3.
-
DavidPostill about 8 yearsWelcome to Super User! This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute.
-
Rad over 7 yearsTo start the exe by a keyboard shortcut:
1. Right-click on the exe and select "Create Shortcut" 2. Move the shortcut to "C:\ProgramData\Microsoft\Windows\Start Menu" or the desktop 3. Right click on the shortcut, go to the Shorcut tab and select a shortcut key
-
Przemyslaw Remin over 6 years5. ALT+F4 to close mouse settings window
-
Leonid Dworzanski almost 5 yearsThis is the best for quicktypers.
-
PAS over 3 yearshighly underrated answer. It's the best!
-
Craig Lambie over 3 yearsThis worked for me on Windows 10 - simply install AutoHotKey and save the above code as an AHK file, double click, and/ or make a shortcut :)
-
Andrew almost 3 yearsAs of June 2021, it still works great on Windows 10. To avoid losing F12, I used control + alt + m instead. So the first line of code would be this: ^!m::