0

My eight-year-old son is left-handed and I am right-handed. I wish to be able to quickly and easily switch primary and secondary mouse buttons from the command line. We use Windows 10. I found this, which provides c and C#* solutions. I found this which provides a solution which does require rebooting, and also provides a link to the Stack Overflow answer. However, it seems to me that this should be possible to do without resorting to a compiled language. I would be happy with a solution using PowerShell, Python, Perl, a nircmd utility, etc., but I'd rather not resort to a compiled language.

Thank you for your help.

Edit: Changed question to add "...or by using a hotkey...", since I ultimately wanted to do this with an Autohotkey hotkey; it turns out that Autohotkey can do the swap itself. I was assuming that the answer would be e.g. a Powershell script, which I would invoke by using an Autohotkey hotkey. See the accepted answer.

ludinom
  • 25

2 Answers2

3

Here is what I came up with for AHK. Just toggles rebinding the mouse buttons with ctrl+alt+m

swap:
swap=false

^!m::
    swap := !swap 

#if !swap
    RButton::LButton
    LButton::RButton
Confuzing
  • 551
2

This is the answer, which was posted on https://superuser.com/a/1357020/790554.

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.

otter.pro
  • 341